The db.testCollection.createIndex( { _id: 1 }, {name: "_id_2", unique: true, background: true} ) fails in Mongo version 2.8.2, but not 3.2.11. The mongo documentation indicates that version 3.4 supports the unique and background attributes.
Mongo 3.4.2 fails ...
> use testDB switched to db testDB > db.testCollection.createIndex( { _id: 1 }, {name: "_id_2", unique: true, background: true} ) { "ok" : 0, "errmsg" : "The field 'unique' is not valid for an _id index specification. Specification: { ns: \"testDB.testCollection\", v: 1, key: { _id: 1.0 }, name: \"_id_2\", unique: true, background: true }", "code" : 197, "codeName" : "InvalidIndexSpecificationOption" } >
Mongo 3.2.11 works ...
> use testDB switched to db testDB > db.testCollection.createIndex( { _id: 1 }, {name: "_id_2", unique: true, background: true} ) { "createdCollectionAutomatically" : false, "numIndexesBefore" : 1, "numIndexesAfter" : 1, "note" : "all indexes already exist", "ok" : 1 } >
Does anyone know about work?
We use the Mongoose Node.js shell to create Mongo indexes, so not adding unique and background attributes is not a parameter.
Hooray!
Ed
source share