How to update a single field in a capped collection in MongoDB?

949 Views Asked by At
db.events.update(
   {upload:0},
   {$set:{upload:1}},
   {multi:true}
)

I am getting the following error even though I am just replacing an integer with another integer.

Cannot change the size of a document in a capped collection: 402 != 406
1

There are 1 best solutions below

0
On BEST ANSWER

it looks like you're inserting a double instead of an int32 (double is 4 byte wider than int32).

from mongodb type documentation :

NumberInt

The mongo shell treats all numbers as floating-point values by default. The mongo shell provides the NumberInt() constructor to explicitly specify 32-bit integers.

To fix this issue, simply change your code to this :

 db.events.update(
   {upload:0},
   {$set:{upload: NumberInt(1)}},
   {multi:true}
)