1
1
# start-bulk-insert-one
2
- operation = pymongo .InsertOne (
3
- {
2
+ operation = InsertOne (
3
+ namespace = "sample_restaurants.restaurants" ,
4
+ document = {
4
5
"name" : "Mongo's Deli" ,
5
6
"cuisine" : "Sandwiches" ,
6
7
"borough" : "Manhattan" ,
10
11
# end-bulk-insert-one
11
12
12
13
# 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" }}
16
18
)
17
19
# end-bulk-update-one
18
20
19
21
# 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" }}
23
26
)
24
27
# end-bulk-update-many
25
28
26
29
# 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 = {
30
34
"name" : "Mongo's Pizza" ,
31
35
"cuisine" : "Pizza" ,
32
36
"borough" : "Brooklyn" ,
36
40
# end-bulk-replace-one
37
41
38
42
# 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
+ )
40
47
# end-bulk-delete-one
41
48
42
49
# 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
+ )
44
54
# end-bulk-delete-many
45
55
46
- # start-bulk-write-mixed
56
+ # start-bulk-write-mixed-collection
47
57
operations = [
48
- pymongo . InsertOne (
49
- {
58
+ InsertOne (
59
+ document = {
50
60
"name" : "Mongo's Deli" ,
51
61
"cuisine" : "Sandwiches" ,
52
62
"borough" : "Manhattan" ,
53
63
"restaurant_id" : "1234"
54
64
}
55
65
),
56
- pymongo . InsertOne (
57
- {
66
+ InsertOne (
67
+ document = {
58
68
"name" : "Mongo's Deli" ,
59
69
"cuisine" : "Sandwiches" ,
60
70
"borough" : "Brooklyn" ,
61
71
"restaurant_id" : "5678"
62
72
}
63
73
),
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" }}
67
77
),
68
- pymongo . DeleteOne (
69
- { "restaurant_id" : "1234" }
78
+ DeleteOne (
79
+ filter = { "restaurant_id" : "1234" }
70
80
)
71
81
]
72
82
73
83
results = restaurants .bulk_write (operations )
74
84
75
85
print (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
77
114
78
115
# start-bulk-write-unordered
79
116
results = 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