[DOCS-15981] [Server] Specify that using collMod to downsize a capped collection only deletes excess documents on the next insertion Created: 23/Mar/23  Updated: 30/Oct/23  Resolved: 14/Jul/23

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

Type: Task Priority: Minor - P4
Reporter: Gregory Wlodarek 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

Issue Links:
Related
related to SERVER-1864 Support Resizing Capped Collections Closed
Participants:
Days since reply: 29 weeks, 5 days ago

 Description   

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.



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

Backports: v6.3, v6.0 (functionality added in v6.0)

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