Pymongo, Python3. Really racking my brains. Tried update_one() and find_one()andupdate(). Tried with the mongo id "_id" as well as with a know ID that I set in each document. Nothing updates in the documents. Can anyone please show me where I m going wrong?
See below for last attempts. Want to loop over all collections and all documents in each collection and update a specific field.
With update_one() and an ID I know to exist in the document:
for collection in collectionNames:
for doc in movie_db[str(collection)].find():
new_path = get_updated_poster()
new_path_url = base_url + new_path
result = movie_db.collection.update_one({'id':int(ID)},{'$set':{'poster_path':new_path_url}})
With find_one_and_update(), even tried with copying an "_id" to no avail (note that I here also have "from bson.objectid import ObjectId" added:
for collection in collectionNames:
for doc in movie_db[str(collection)].find():
new_path = get_updated_poster()
new_path_url = base_url + new_path
result = movie_db.collection.update_one(
{"_id":ObjectId(id)},
{"$set": {
"poster_path": new_path
}
}, upsert=False)