Remove attribute from all MongoDB documents using Python and PyMongo -
in mongodb, bunch of these documents exist:
{ "_id" : objectid("5341eaae6e59875a9c80fa68"), "parent" : { "tokeep" : 0, "toremove" : 0 } }
i want remove parent.toremove
attribute in every single one.
using mongodb shell, can accomplish using:
db.collection.update({},{$unset: {'parent.toremove':1}},false,true)
but how do within python?
app = flask(__name__) mongo = pymongo(app) mongo.db.collection.update({},{$unset: {'parent.toremove':1}},false,true)
returns following error:
file "myprogram.py", line 46 mongo.db.collection.update({},{$unset: {'parent.toremove':1}},false,true) ^ syntaxerror: invalid syntax
put quotes around $unset
, name parameter you're including (multi
) , use correct syntax true:
mongo.db.collection.update({}, {'$unset': {'parent.toremove':1}}, multi=true)
Comments
Post a Comment