|
Another case is creating a TTL index on a capped collection, which is can be created but doesn't actually achieve anything productive.
> db.createCollection("test", {capped:true, size: 102400})
|
{ "ok" : 1 }
|
> db.test.ensureIndex({foo:1}, {expireAfterSeconds: 10})
|
{
|
"createdCollectionAutomatically" : false,
|
"numIndexesBefore" : 1,
|
"numIndexesAfter" : 2,
|
"ok" : 1
|
}
|
> db.test.insert({foo:new Date()})
|
WriteResult({ "nInserted" : 1 })
|
2016-01-19T18:17:11.210+1100 I STORAGE [TTLMonitor] failing remove on a capped ns test.test
|
2016-01-19T18:17:11.210+1100 E INDEX [TTLMonitor] Error processing ttl index: { v: 1, key: { foo: 1.0 }, name: "foo_1", ns: "test.test", expireAfterSeconds: 10.0 } -- 10089 cannot remove from a capped collection
|
If such indexes were disallowed in the first place, it could have avoided the effort on SERVER-11266, SERVER-16749 and SERVER-20920.
In addition, the TTL docs state that creating such an index isn't possible, which isn't strictly true until this ticket is resolved.
You cannot create a TTL index on a capped collection because MongoDB cannot remove documents from a capped collection.
|
|
One more example of the same issue:
> db.notification.getIndexes()[1]
|
{
|
"v" : 1,
|
"key" : {
|
"_cls" : 1,
|
"membership" : 1
|
},
|
"ns" : "closeio.notification",
|
"name" : "_cls_1_membership_1",
|
"background" : false,
|
"dropDups" : false
|
}
|
> db.notification.ensureIndex({ _cls: 1, membership: 1 })
|
{ "numIndexesBefore" : 14, "note" : "all indexes already exist", "ok" : 1 }
|
> db.notification.ensureIndex({ _cls: 1, membership: 1 }, { background: true })
|
{ "numIndexesBefore" : 14, "note" : "all indexes already exist", "ok" : 1 }
|
> db.notification.ensureIndex({ _cls: 1, membership: 1 }, { whatever: true })
|
{
|
"ok" : 0,
|
"errmsg" : "Index with name: _cls_1_membership_1 already exists with different options",
|
"code" : 85
|
}
|
> db.notification.ensureIndex({ _cls: 1, membership: 1, whatever:1 }, { whatever: true })
|
{
|
"createdCollectionAutomatically" : false,
|
"numIndexesBefore" : 14,
|
"numIndexesAfter" : 15,
|
"ok" : 1
|
}
|
> db.notification.getIndexes()[14]
|
{
|
"v" : 1,
|
"key" : {
|
"_cls" : 1,
|
"membership" : 1,
|
"whatever" : 1
|
},
|
"name" : "_cls_1_membership_1_whatever_1",
|
"ns" : "closeio.notification",
|
"whatever" : true
|
}
|
1. Calling ensureIndex with an unsupported option shouldn't consider the spec different from the existing one (i.e. the error shouldn't occur).
2. Options that aren't supported shouldn't be stored on the index spec.
|