-
Type: Bug
-
Resolution: Duplicate
-
Priority: Minor - P4
-
None
-
Affects Version/s: 2.6.0-rc1
-
Component/s: Index Maintenance
-
Query
-
ALL
For the most part, ensureIndex on an existing index but with different options error, but if the only difference is the name, it doesn't error.
> db.test.ensureIndex( { foo: 1 } ) WriteResult({ "nInserted" : 1 }) > db.test.ensureIndex( { foo: 1 }, { unique: true } ) WriteResult({ "nInserted" : 0, "writeError" : { "code" : 67, "errmsg" : "Index with name: foo_1 already exists with different options" } }) > db.test.ensureIndex( { foo: 1 }, { name: "kay"} ) WriteResult({ "nInserted" : 0 }) > db.test.getIndexes() [ { "v" : 1, "key" : { "_id" : 1 }, "name" : "_id_", "ns" : "test.test" }, { "v" : 1, "key" : { "foo" : 1 }, "name" : "foo_1", "ns" : "test.test" } ]
Given that the check seems to be by name, I can see that if the names differ, then of course, it won't do the check but wasn't sure.
If this is the expected behavior, I can just simply state that if an index already exists with the same name, ensureIndex will error if the key specs or the options differ. instead of having two separate error cases of (same key spec, different options) = error and (different key spec, same name) = error
- duplicates
-
SERVER-33149 createIndexes fails to report an error when index is not created with the specified name
- Closed