Permalink
Browse files

Merge pull request #828 from aheckmann/backgroundIndexes

[ready] create indexes in background by default
  • Loading branch information...
2 parents cbd603a + ecd33ac commit 6e9d36d4cd8c8c71571d893c1b212558a2b7c76f @rauchg rauchg committed Apr 12, 2012
Showing with 13 additions and 4 deletions.
  1. +6 −1 lib/schema.js
  2. +7 −3 test/schema.test.js
View
@@ -425,7 +425,9 @@ Schema.prototype.__defineGetter__('indexes', function () {
if (index !== false && index !== null){
var field = {};
field[prefix + i] = '2d' === index ? index : 1;
- indexes.push([field, 'Object' === index.constructor.name ? index : {} ]);
+ var options = 'Object' === index.constructor.name ? index : {};
+ if (!('background' in options)) options.background = true;
+ indexes.push([field, options]);
}
}
}
@@ -434,6 +436,9 @@ Schema.prototype.__defineGetter__('indexes', function () {
if (prefix) {
fixSubIndexPaths(schema, prefix);
} else {
+ schema._indexes.forEach(function (index) {
+ if (!('background' in index[1])) index[1].background = true;
+ });
indexes = indexes.concat(schema._indexes);
}
}
View
@@ -793,14 +793,18 @@ module.exports = {
var Tobi = new Schema({
name: { type: String, index: true }
, last: { type: Number, sparse: true }
+ , nope: { type: String, index: { background: false }}
});
Tobi.index({ firstname: 1, last: 1 }, { unique: true });
+ Tobi.index({ firstname: 1, nope: 1 }, { unique: true, background: false });
Tobi.indexes.should.eql([
- [{ name: 1 }, {}]
- , [{ last: 1 }, { sparse: true }]
- , [{ firstname: 1, last: 1}, {unique: true}]
+ [{ name: 1 }, { background: true }]
+ , [{ last: 1 }, { sparse: true, background :true }]
+ , [{ nope: 1 }, { background : false}]
+ , [{ firstname: 1, last: 1}, {unique: true, background: true }]
+ , [{ firstname: 1, nope: 1 }, { unique: true, background: false }]
]);
},

0 comments on commit 6e9d36d

Please sign in to comment.