The Collection.save method has been removed. For better performance, use insert_one to insert new documents and update_one to update existing ones. If you need a drop-in replacement that handles both (upsert), you can implement a custom function using replace_one with upsert=True.
# Old
doc = collection.find_one({"_id": "some id"})
doc["some field"] = <some value>
db.collection.save(doc)
# New (Recommended)
result = collection.update_one({"_id": "some id"}, {"$set": {"some field": <some value>}})
# Manual save implementation if refactoring is not possible
def save(doc):
if '_id' in doc:
collection.replace_one({'_id': doc['_id']}, doc, upsert=True)
return doc['_id']
else:
res = collection.insert_one(doc)
return res.inserted_id