In my MongoDB there is a bunch of these documents:
{ "_id" : ObjectId("5341eaae6e59875a9c80fa68"), "parent" : { "tokeep" : 0, "toremove" : 0 } }
I want to remove the parent.toremove attribute in each of them.
Using the MongoDB shell, I can accomplish this using:
db.collection.update({},{$unset: {'parent.toremove':1}},false,true)
But how to do it in Python?
app = Flask(__name__) mongo = PyMongo(app) mongo.db.collection.update({},{$unset: {'parent.toremove':1}},false,true)
returns the following error:
File "myprogram.py", line 46 mongo.db.collection.update({},{$unset: {'parent.toremove':1}},false,true) ^ SyntaxError: invalid syntax
python mongodb pymongo
Caroline
source share