Reputation: 1253
I'm using mongodb 3.6.3
db.version() 3.6.3
I have test collection:
> db.test.find()
{ "_id" : ObjectId("5c582787e504df9ad201ba77"), "val" : 0.25 }
{ "_id" : ObjectId("5c582789e504df9ad201ba78"), "val" : 1 }
{ "_id" : ObjectId("5c58278be504df9ad201ba79"), "val" : 10 }
{ "_id" : ObjectId("5c58278fe504df9ad201ba7a"), "val" : 11122 }
And I want to divide all values. Due for this I've tried to use updateMany
> db.test.updateMany({}, {$mul: {val: 0.5}})
2019-02-04T17:08:27.548+0500 TypeError: Property 'updateMany' of object local.test is not a function
> db.test.update({}, {$mul: {val: 0.5}}, {multi:true})
WriteResult({ "nMatched" : 4, "nUpserted" : 0, "nModified" : 4 })
> db.test.find()
{ "_id" : ObjectId("5c582787e504df9ad201ba77"), "val" : 0.125 }
{ "_id" : ObjectId("5c582789e504df9ad201ba78"), "val" : 0.5 }
{ "_id" : ObjectId("5c58278be504df9ad201ba79"), "val" : 5 }
{ "_id" : ObjectId("5c58278fe504df9ad201ba7a"), "val" : 5561 }
Why there is no updateMany function?
Upvotes: 2
Views: 1463
Reputation: 643
updateMany has been introduced in version 3.2 since you're using mongo shell with version 2.6.10, it's missing there. You need to update your CLI and it should work as expected.
Upvotes: 2