Introduction to MongoDB in Python
Filip Schouwenaars
Machine Learning Researcher
from pymongo import InsertOne, UpdateOne # import classesoperations = [ InsertOne({ # operation 1 "title": "Dune", "genre": ["action", "adventure", "drama"], "release_year": 2021, "rating": 8.0, "won_oscar": False }), UpdateOne( # operation 2 { "title": "Titanic" }, { "$set": { "won_oscar": True } } ) ]result = mov.bulk_write(operations) # pass list to bulk_write
print(result.inserted_count)
1
print(result.modified_count)
1
Keep in mind
Use any mix of:
InsertOne()UpdateOne() / UpdateMany() / ReplaceOne()DeleteOne() / DeleteMany()ReplaceOne()Great for:
Introduction to MongoDB in Python