In a MongoDB index, what do the options "safe" and "force" mean? -


i'm looking @ our mongo (2.4.10) indexes, using collection.getindexes(). see options aren't discussed in doc can find. specifically, see options "safe" , "force". example below:

{     "v" : 1,     "name" : "status_1",     "key" : {         "status" : numberlong(1)     },     "ns" : "db.mycoll",     "force" : true,     "background" : true }, 

what "force" , "safe" mean?

the options mention ("force" , "safe") not valid index options mongodb 2.4.

they resulted developer accidentally ensuring index including these index options (perhaps having intended fields part of index criteria?).

you can reproduce outcome in mongo shell:

> db.foo.ensureindex({foo: true}, {force: true, safe: true}) {     "createdcollectionautomatically" : true,     "numindexesbefore" : 1,     "numindexesafter" : 2,     "ok" : 1 }  > db.foo.getindexes() [     {         "v" : 1,         "key" : {             "_id" : 1         },         "name" : "_id_",         "ns" : "stack.foo"     },     {         "v" : 1,         "key" : {             "foo" : true         },         "name" : "foo_true",         "ns" : "stack.foo",         "force" : true,         "safe" : true     } ] > 

unknown index options ignored (at least @ mongodb 3.0), while confusing impact benign. unfortunately way remove invalid options dropping & rebuilding affected index(es) there no api changing existing index.

it's possible index option validation may added in future mongodb release, should noted compatibility change in release notes. example, mongodb 2.6 has several index changes including better field name validation , enforcement of index key length.


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -