6 var start = require('../../common')
7 , mongoose = start.mongoose
8 , should = require('should')
9 , Schema = mongoose.Schema;
15 mongoose.model('NativeDriverTest', new Schema({
25 'test that trying to implement a sparse index works': function () {
27 , NativeTestCollection = db.model('NativeDriverTest');
29 NativeTestCollection.collection.ensureIndex({ title: 1 }, { sparse: true }, function (err) {
30 should.strictEqual(!!err, false);
31 NativeTestCollection.collection.getIndexes(function (err, indexes) {
33 should.strictEqual(!!err, false);
34 indexes.should.be.instanceof(Object);
35 indexes['title_1'].should.eql([['title', 1]]);
40 'test that the -native traditional ensureIndex spec syntax for fields works': function () {
42 , NativeTestCollection = db.model('NativeDriverTest');
44 NativeTestCollection.collection.ensureIndex([['a', 1]], function () {
49 'unique index fails passes error': function () {
51 , schema = new Schema({ title: String })
52 , NativeTestCollection = db.model('NativeDriverTestUnique', schema)
54 NativeTestCollection.create({ title: 'x' }, {title:'x'}, function (err) {
55 should.strictEqual(!!err, false);
57 NativeTestCollection.collection.ensureIndex({ title: 1 }, { unique: true }, function (err) {
58 ;/E11000 duplicate key error index/.test(err.message).should.equal(true);