-
Type: Task
-
Resolution: Fixed
-
Priority: Minor - P4
-
Affects Version/s: None
-
Labels:
-
Environment:MongoDB 5.0.6
Capped collections documentation at https://www.mongodb.com/docs/manual/core/capped-collections/ specifies that
"TTL indexes are not compatible with capped collections."
However, the following tests with an empty database (i.e. no collections in the database when the test is done):
{{> show collections
> db.createCollection( "c",
)
{ "ok" : 1 }> db.c.isCapped()
true
> db.c.createIndex(
,
{ expireAfterSeconds: 3600 })
{ "numIndexesBefore" : 1, "numIndexesAfter" : 2, "createdCollectionAutomatically" : false, "ok" : 1 }> db.c.getIndexes()
[
{
"v" : 2,
"key" :
,
"name" : "id"
},
{
"v" : 2,
"key" :
,
"name" : "date_1",
"expireAfterSeconds" : 3600
}
]}}
So, I understands the documentation is not correct or "compatibility" should be explained better (i.e. the index can be created but expiration on it is ignored).
With MongoDB 7.0.0-rc4 and MongoDB 6.0.7
Enterprise replset [direct: primary] test> db.createCollection( "c", {capped:true, size:100000})
{ ok: 1 }
Enterprise replset [direct: primary] test> db.c.isCapped()
true
Enterprise replset [direct: primary] test> db.c.createIndex({"date":1},{expireAfterSeconds:3600})
MongoServerError: Cannot create TTL index on a capped collection
With MongoDB 5.0.18:
test> db.createCollection( "c", {capped:true, size:100000})
{ ok: 1 }
test> db.c.isCapped()
true
test> db.c.createIndex({"date":1},{expireAfterSeconds:3600})
date_1
Will update the 5.0 docs and backport to 4.4 and 4.2