-
Type: Task
-
Resolution: Fixed
-
Priority: Minor - P4
-
Affects Version/s: None
-
Component/s: Server
-
Labels:
See this Slack conversation around this confusion: https://mongodb.slack.com/archives/C2RCHGB2L/p1679514081458219
Hi, I'm adding tests for capped collections in mongosync, and I found what may be a bug with modifying the maximum amount of documents a capped collection can store. To reproduce it, run something like: db.createCollection( "cap", { capped: true, size: 10000000, max: 5 } ) db.cap.insertOne({"test":3}) db.cap.insertOne({"test":3}) db.cap.insertOne({"test":3}) db.cap.insertOne({"test":3}) db.cap.insertOne({"test":3}) db.runCommand({"collMod": "cap", "cappedSize": 100000000, "cappedMax":2}) //I'd expect there to be 2 documents in the collection, but there are still 5. replset [direct: primary] test> db.cap.find() [ { _id: ObjectId("641b57cf4fec0a5858b5f8a0"), test: 3 }, { _id: ObjectId("641b57d04fec0a5858b5f8a1"), test: 3 }, { _id: ObjectId("641b57d14fec0a5858b5f8a2"), test: 3 }, { _id: ObjectId("641b57d24fec0a5858b5f8a3"), test: 3 }, { _id: ObjectId("641b57d24fec0a5858b5f8a4"), test: 3 } ] //After inserting one more document, then it truncates to the correct max size db.cap.insertOne({"test":4}) [ { _id: ObjectId("641b57f14fec0a5858b5f8a5"), test: 3 }, { _id: ObjectId("641b59564fec0a5858b5f8a7"), test: 4 } ] Essentially changing a capped collections max number of documents to be smaller than the number of documents that it currently contains doesn't seem to remove documents, until a new insert is processed. Is this expected?
This is the expected behaviour.
- related to
-
SERVER-1864 Support Resizing Capped Collections
- Closed