Ncastro340
Ncastro340

Reputation: 107

Update mongo collection with $set

Trying to update a collection and getting invalid syntax from '$'. This script works correctly inside robomongo GUI but not from the terminal..? Probably something simple but I can't seem to figure out why it's giving an error.

    collection.update({'title': "Super excited"},{ $set: {"fb_count": 300}}, {multi: true})

Upvotes: 4

Views: 1602

Answers (3)

Sid Johnson
Sid Johnson

Reputation: 161

In my case, with the same problem, putting the single quotes around $set alone did the trick, although I have not seen that as required in the documentation.

Upvotes: 0

kakashi
kakashi

Reputation: 317

try following code, and I think you can specify multi as argument

collection.update({'title': "Super excited"}, {'$set': {"fb_count": 300}}, multi=True)

pleaser refer to pymongo.collection.Collection.update

Upvotes: 4

Max Noel
Max Noel

Reputation: 8910

You're missing quotes around "$set" (and "multi").

Upvotes: 1

Related Questions