11# start-bulk-insert-one
2- operation = pymongo .InsertOne (
3- {
2+ operation = InsertOne (
3+ namespace = "sample_restaurants.restaurants" ,
4+ document = {
45 "name" : "Mongo's Deli" ,
56 "cuisine" : "Sandwiches" ,
67 "borough" : "Manhattan" ,
1011# end-bulk-insert-one
1112
1213# start-bulk-update-one
13- operation = pymongo .UpdateOne (
14- { "name" : "Mongo's Deli" },
15- { "$set" : { "cuisine" : "Sandwiches and Salads" }},
14+ operation = UpdateOne (
15+ namespace = "sample_restaurants.restaurants" ,
16+ filter = { "name" : "Mongo's Deli" },
17+ update = { "$set" : { "cuisine" : "Sandwiches and Salads" }}
1618)
1719# end-bulk-update-one
1820
1921# start-bulk-update-many
20- operation = pymongo .UpdateMany (
21- { "name" : "Mongo's Deli" },
22- { "$set" : { "cuisine" : "Sandwiches and Salads" }},
22+ operation = UpdateMany (
23+ namespace = "sample_restaurants.restaurants" ,
24+ filter = { "name" : "Mongo's Deli" },
25+ update = { "$set" : { "cuisine" : "Sandwiches and Salads" }}
2326)
2427# end-bulk-update-many
2528
2629# start-bulk-replace-one
27- operation = pymongo .ReplaceOne (
28- { "restaurant_id" : "1234" },
29- {
30+ operation = ReplaceOne (
31+ namespace = "sample_restaurants.restaurants" ,
32+ filter = { "restaurant_id" : "1234" },
33+ replacement = {
3034 "name" : "Mongo's Pizza" ,
3135 "cuisine" : "Pizza" ,
3236 "borough" : "Brooklyn" ,
3640# end-bulk-replace-one
3741
3842# start-bulk-delete-one
39- operation = pymongo .DeleteOne ({ "restaurant_id" : "5678" })
43+ operation = DeleteOne (
44+ namespace = "sample_restaurants.restaurants" ,
45+ filter = { "restaurant_id" : "5678" }
46+ )
4047# end-bulk-delete-one
4148
4249# start-bulk-delete-many
43- operation = pymongo .DeleteMany ({ "name" : "Mongo's Deli" })
50+ operation = DeleteMany (
51+ namespace = "sample_restaurants.restaurants" ,
52+ filter = { "name" : "Mongo's Deli" }
53+ )
4454# end-bulk-delete-many
4555
46- # start-bulk-write-mixed
56+ # start-bulk-write-mixed-collection
4757operations = [
48- pymongo . InsertOne (
49- {
58+ InsertOne (
59+ document = {
5060 "name" : "Mongo's Deli" ,
5161 "cuisine" : "Sandwiches" ,
5262 "borough" : "Manhattan" ,
5363 "restaurant_id" : "1234"
5464 }
5565 ),
56- pymongo . InsertOne (
57- {
66+ InsertOne (
67+ document = {
5868 "name" : "Mongo's Deli" ,
5969 "cuisine" : "Sandwiches" ,
6070 "borough" : "Brooklyn" ,
6171 "restaurant_id" : "5678"
6272 }
6373 ),
64- pymongo . UpdateMany (
65- { "name" : "Mongo's Deli" },
66- { "$set" : { "cuisine" : "Sandwiches and Salads" }},
74+ UpdateMany (
75+ filter = { "name" : "Mongo's Deli" },
76+ update = { "$set" : { "cuisine" : "Sandwiches and Salads" }}
6777 ),
68- pymongo . DeleteOne (
69- { "restaurant_id" : "1234" }
78+ DeleteOne (
79+ filter = { "restaurant_id" : "1234" }
7080 )
7181]
7282
7383results = restaurants .bulk_write (operations )
7484
7585print (results )
76- # end-bulk-write-mixed
86+ # end-bulk-write-mixed-collection
87+
88+
89+ # start-bulk-write-mixed-client
90+ operations = [
91+ InsertOne (
92+ namespace = "sample_mflix.movies" ,
93+ document = {
94+ "title" : "Minari" ,
95+ "runtime" : 217 ,
96+ "genres" : ["Drama" , "Comedy" ]
97+ }
98+ ),
99+ UpdateOne (
100+ namespace = "sample_mflix.movies" ,
101+ filter = { "title" : "Minari" },
102+ update = { "$set" : { "runtime" : 117 }}
103+ ),
104+ DeleteMany (
105+ namespace = "sample_restaurants.restaurants" ,
106+ filter = { "cuisine" : "French" }
107+ )
108+ ]
109+
110+ results = client .bulk_write (operations )
111+
112+ print (results )
113+ # end-bulk-write-mixed-client
77114
78115# start-bulk-write-unordered
79116results = restaurants .bulk_write (operations , ordered = False )
80- # end-bulk-write-unordered
117+ # end-bulk-write-unordered
118+
119+ # start-bulk-write-verbose
120+ results = client .bulk_write (operations , verbose_results = True )
121+ # end-bulk-write-verbose
0 commit comments