Cannot get updateMany() command to work - Chapter 3 Examples

Hello,

I am trying to go through the examples at the end of Chapter 3 of M001, MongoDB Basics using the in browser IDE and I can’t get the updateMany() command to work.

Here is the command and the error that I get:

MongoDB Enterprise atlas-ll7v9s-shard-0:PRIMARY> db.zips.updateMany(
… { “city”: “ALBANY” },
… {“state”: “NY”},
… { “$set”: { “capital”: true } },
… { upsert: true })
uncaught exception: Error: the update operation document must contain atomic operators :
DBCollection.prototype.updateMany@src/mongo/shell/crud_api.js:655:19
@(shell):1:1

I that that $set is an atomic operator so I’m not sure what I’m doing wrong.

Any help would be much appreciated!

Thanks!

Hi there, @Troy_McKenna,

updateMany expects:

db.coll.updateMany({query...}, {updates...}, {options..})

there is an issue in the <query> part,:

db.zips.updateMany(
{ “city”: “ALBANY” },
{“state”: “NY”}

should be

db.zips.updateMany(
{ “city”: “ALBANY” , “state”: “NY”},

and the rest seems fine, but get back if there are any troubles.

3 Likes

Thank you SO much @santimir!
That worked! Simple fix but I sure couldn’t see it! Haha!
Thanks a million!

2 Likes

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.