1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
/**
* Module dependencies.
*/
var start = require('../../common')
, mongoose = start.mongoose
, should = require('should')
, Schema = mongoose.Schema;
/**
* Setup.
*/
mongoose.model('NativeDriverTest', new Schema({
title: String
}));
/**
* Test.
*/
module.exports = {
'test that trying to implement a sparse index works': function () {
var db = start()
, NativeTestCollection = db.model('NativeDriverTest');
NativeTestCollection.collection.ensureIndex({ title: 1 }, { sparse: true }, function (err) {
should.strictEqual(!!err, false);
NativeTestCollection.collection.getIndexes(function (err, indexes) {
db.close();
should.strictEqual(!!err, false);
indexes.should.be.instanceof(Object);
indexes['title_1'].should.eql([['title', 1]]);
});
});
},
'test that the -native traditional ensureIndex spec syntax for fields works': function () {
var db = start()
, NativeTestCollection = db.model('NativeDriverTest');
NativeTestCollection.collection.ensureIndex([['a', 1]], function () {
db.close();
});
},
'unique index fails passes error': function () {
var db = start()
, schema = new Schema({ title: String })
, NativeTestCollection = db.model('NativeDriverTestUnique', schema)
NativeTestCollection.create({ title: 'x' }, {title:'x'}, function (err) {
should.strictEqual(!!err, false);
NativeTestCollection.collection.ensureIndex({ title: 1 }, { unique: true, safe: true }, function (err) {
db.close();
;/E11000 duplicate key error index/.test(err.message).should.equal(true);
});
});
}
};
|