Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB, Updating a capped collection

Tags:

mongodb

nosql

does anyone know a way to update a capped collection in Mongo3.2? I had this working in 2.x where by I updated a collection, and basically removed all its content so I knew it had been processed. This would then age out.

When I do the same in 3.2 I get the following error on the command line.

Cannot change the size of a document in a capped collection: 318 != 40

Here you can see I'm shrinking the document from 318bytes to 40bytes.

Is there a way to do this?

like image 551
Jonathan Perrozzi Avatar asked Oct 28 '25 21:10

Jonathan Perrozzi


2 Answers

As mentioned in mongodb docs

Changed in version 3.2.

If an update or a replacement operation changes the document size, the operation will fail.

https://docs.mongodb.com/manual/core/capped-collections/

So your operation is changing the size of the capped collection, which is not allowed in mongodb 3.2+

like image 130
Puneet Singh Avatar answered Oct 30 '25 15:10

Puneet Singh


Shrinking a document in a capped collection is no longer allowed in 3.2. I did not find anything related to this in the documentation, but there is a rationale at https://jira.mongodb.org/browse/SERVER-20529 (basicalling shrinking document cannot be rolled back)

Your only option is to find a same-size update, for example update a boolean.

like image 32
Sebastien Alborini Avatar answered Oct 30 '25 15:10

Sebastien Alborini



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!