2
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
Neil Lunn
  • 148,042
  • 36
  • 346
  • 317
Sathish
  • 409
  • 8
  • 24
  • Are you sure you are not updating integer value `{upload:0}` to double value `{upload:1}` ? You can check the type by running `db.events.find({upload: {$type: 'int'}})` and see if it returns any document(s) for verification. Are you running queries in shell ? – s7vr May 18 '17 at 17:48

1 Answers1

3

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}
)
felix
  • 9,007
  • 7
  • 41
  • 62