[DOCS-15313] Capped collection documentation is not correct Created: 04/May/22  Updated: 30/Oct/23  Resolved: 14/Jul/23

Status: Closed
Project: Documentation
Component/s: manual, Server
Affects Version/s: None
Fix Version/s: Server_Docs_20231030

Type: Task Priority: Minor - P4
Reporter: Fermín Galán Assignee: Nick Villahermosa
Resolution: Fixed Votes: 0
Labels: quick-win, server-docs-bug-bash
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

MongoDB 5.0.6


Participants:
Days since reply: 29 weeks, 5 days ago

 Description   

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",

{ capped: true, size: 100000 }

)

{ "ok" : 1 }

> db.c.isCapped()
true
> db.c.createIndex(

{ "date": 1 }

,

{ expireAfterSeconds: 3600 }

)

{ "numIndexesBefore" : 1, "numIndexesAfter" : 2, "createdCollectionAutomatically" : false, "ok" : 1 }

> db.c.getIndexes()
[
{
"v" : 2,
"key" :

{ "_id" : 1 }

,
"name" : "id"
},
{
"v" : 2,
"key" :

{ "date" : 1 }

,
"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



 Comments   
Comment by Nick Villahermosa [ 14/Jul/23 ]

Backports: v4.4

Comment by Jeffrey Allen [ 04/May/22 ]

I found some additional context in Slack that I'll capture here in the ticket so we don't lose it due to retention policy:

gregory.wlodarek@mongodb.com wrote:

You can create a TTL index on a capped collection, but it won't do any TTL deletes.

My understanding is that we should update the language on the capped collection page to not make a blanket statement that TTL indexes are incompatible, but that the TTL index won't perform deletes.

Comment by Fermín Galán [ 04/May/22 ]

Sorry the formatting of the code part... I'm not used to JIRA syntax. I hope it is clear, but in negative case please tell me and I can provide more information.

Generated at Thu Feb 08 08:12:34 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.