Python Forum

Full Version: Convert a mongo db scrip to python equivalent
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi ,

I'm using below script in Robot mongo to update key value to and ObjectId type.
This is working perfectly

db.getCollection('tags').find({oid:{$not: {$type: 7}}}).forEach(function(x){
x.oid = ObjectId(x.oid);
db.getCollection('tags').save(x);
});

But I need to code same thing in python.
below python script get the collection I need to convert the objectId type but I'm not sure how to update it

db = client[db_name]
my_coll = db['tags']
Query={"oid":{"$not": {"$type": 7}}}
list1=my_coll.find(Query)
for x in list1:
pprint(x )




any support appreciated
First of all which library do you use for MongoDB in your program?