1
- #![ allow( missing_docs) ]
2
-
3
1
use std:: borrow:: Borrow ;
4
2
5
3
use serde:: { Deserialize , Serialize } ;
@@ -16,25 +14,47 @@ use crate::{
16
14
Namespace ,
17
15
} ;
18
16
17
+ /// The supported options for [`bulk_write`](crate::Client::bulk_write).
19
18
#[ skip_serializing_none]
20
19
#[ derive( Clone , Debug , Default , Deserialize , Serialize ) ]
21
20
#[ serde( rename_all = "camelCase" ) ]
22
21
#[ non_exhaustive]
23
22
pub struct BulkWriteOptions {
23
+ /// Whether the operations should be performed in the order in which they were specified. If
24
+ /// true, no more writes will be performed if a single write fails. If false, writes will
25
+ /// continue to be attempted if a single write fails.
26
+ ///
27
+ /// Defaults to true.
24
28
#[ serialize_always]
25
29
#[ serde( serialize_with = "serialize_bool_or_true" ) ]
26
30
pub ordered : Option < bool > ,
31
+
32
+ /// Whether document-level validation should be bypassed.
33
+ ///
34
+ /// Defaults to false.
27
35
pub bypass_document_validation : Option < bool > ,
36
+
37
+ /// An arbitrary comment to help trace the operation through the database profiler, currentOp
38
+ /// and logs.
28
39
pub comment : Option < Bson > ,
40
+
41
+ /// A map of parameter names and values to apply to all operations within the bulk write.
42
+ /// Values must be constant or closed expressions that do not reference document fields.
43
+ /// Parameters can then be accessed as variables in an aggregate expression context (e.g.
44
+ /// "$$var").
29
45
#[ serde( rename = "let" ) ]
30
46
pub let_vars : Option < Document > ,
47
+
48
+ /// The write concern to use for this operation.
31
49
pub write_concern : Option < WriteConcern > ,
32
50
}
33
51
52
+ /// A single write to be performed within a [`bulk_write`](crate::Client::bulk_write) operation.
34
53
#[ skip_serializing_none]
35
54
#[ derive( Clone , Debug , Serialize ) ]
36
55
#[ serde( untagged) ]
37
56
#[ non_exhaustive]
57
+ #[ allow( missing_docs) ]
38
58
pub enum WriteModel {
39
59
InsertOne ( InsertOneModel ) ,
40
60
UpdateOne ( UpdateOneModel ) ,
@@ -44,17 +64,20 @@ pub enum WriteModel {
44
64
DeleteMany ( DeleteManyModel ) ,
45
65
}
46
66
67
+ /// Inserts a single document.
47
68
#[ skip_serializing_none]
48
69
#[ derive( Clone , Debug , Serialize , TypedBuilder ) ]
49
70
#[ cfg_attr( test, derive( Deserialize ) ) ]
50
71
#[ serde( rename_all = "camelCase" ) ]
51
72
#[ builder( field_defaults( default , setter( into) ) ) ]
52
73
#[ non_exhaustive]
53
74
pub struct InsertOneModel {
75
+ /// The namespace on which the insert should be performed.
54
76
#[ serde( skip_serializing) ]
55
77
#[ builder( !default ) ]
56
78
pub namespace : Namespace ,
57
79
80
+ /// The document to insert.
58
81
#[ builder( !default ) ]
59
82
pub document : Document ,
60
83
}
@@ -65,30 +88,41 @@ impl From<InsertOneModel> for WriteModel {
65
88
}
66
89
}
67
90
91
+ /// Updates a single document.
68
92
#[ skip_serializing_none]
69
93
#[ derive( Clone , Debug , Serialize , TypedBuilder ) ]
70
94
#[ cfg_attr( test, derive( Deserialize ) ) ]
71
95
#[ serde( rename_all = "camelCase" ) ]
72
96
#[ builder( field_defaults( default , setter( into) ) ) ]
73
97
#[ non_exhaustive]
74
98
pub struct UpdateOneModel {
99
+ /// The namespace on which the update should be performed.
75
100
#[ serde( skip_serializing) ]
76
101
#[ builder( !default ) ]
77
102
pub namespace : Namespace ,
78
103
104
+ /// The filter to use. The first document matching this filter will be updated.
79
105
#[ builder( !default ) ]
80
106
pub filter : Document ,
81
107
108
+ /// The update to perform.
82
109
#[ serde( rename( serialize = "updateMods" ) ) ]
83
110
#[ builder( !default ) ]
84
111
pub update : UpdateModifications ,
85
112
113
+ /// A set of filters specifying to which array elements an update should apply.
86
114
pub array_filters : Option < Array > ,
87
115
116
+ /// The collation to use.
88
117
pub collation : Option < Document > ,
89
118
119
+ /// The index to use. Specify either the index name as a string or the index key pattern. If
120
+ /// specified, then the query system will only consider plans using the hinted index.
90
121
pub hint : Option < Bson > ,
91
122
123
+ /// Whether a new document should be created if no document matches the filter.
124
+ ///
125
+ /// Defaults to false.
92
126
pub upsert : Option < bool > ,
93
127
}
94
128
@@ -98,30 +132,41 @@ impl From<UpdateOneModel> for WriteModel {
98
132
}
99
133
}
100
134
135
+ /// Updates multiple documents.
101
136
#[ skip_serializing_none]
102
137
#[ derive( Clone , Debug , Serialize , TypedBuilder ) ]
103
138
#[ cfg_attr( test, derive( Deserialize ) ) ]
104
139
#[ serde( rename_all = "camelCase" ) ]
105
140
#[ builder( field_defaults( default , setter( into) ) ) ]
106
141
#[ non_exhaustive]
107
142
pub struct UpdateManyModel {
143
+ /// The namespace on which the update should be performed.
108
144
#[ serde( skip_serializing) ]
109
145
#[ builder( !default ) ]
110
146
pub namespace : Namespace ,
111
147
148
+ /// The filter to use. All documents matching this filter will be updated.
112
149
#[ builder( !default ) ]
113
150
pub filter : Document ,
114
151
152
+ /// The update to perform.
115
153
#[ serde( rename( serialize = "updateMods" ) ) ]
116
154
#[ builder( !default ) ]
117
155
pub update : UpdateModifications ,
118
156
157
+ /// A set of filters specifying to which array elements an update should apply.
119
158
pub array_filters : Option < Array > ,
120
159
160
+ /// The collation to use.
121
161
pub collation : Option < Document > ,
122
162
163
+ /// The index to use. Specify either the index name as a string or the index key pattern. If
164
+ /// specified, then the query system will only consider plans using the hinted index.
123
165
pub hint : Option < Bson > ,
124
166
167
+ /// Whether a new document should be created if no document matches the filter.
168
+ ///
169
+ /// Defaults to false.
125
170
pub upsert : Option < bool > ,
126
171
}
127
172
@@ -131,28 +176,38 @@ impl From<UpdateManyModel> for WriteModel {
131
176
}
132
177
}
133
178
179
+ /// Replaces a single document.
134
180
#[ skip_serializing_none]
135
181
#[ derive( Clone , Debug , Serialize , TypedBuilder ) ]
136
182
#[ cfg_attr( test, derive( Deserialize ) ) ]
137
183
#[ serde( rename_all = "camelCase" ) ]
138
184
#[ builder( field_defaults( default , setter( into) ) ) ]
139
185
#[ non_exhaustive]
140
186
pub struct ReplaceOneModel {
187
+ /// The namespace on which the replace should be performed.
141
188
#[ serde( skip_serializing) ]
142
189
#[ builder( !default ) ]
143
190
pub namespace : Namespace ,
144
191
192
+ /// The filter to use.
145
193
#[ builder( !default ) ]
146
194
pub filter : Document ,
147
195
196
+ /// The replacement document.
148
197
#[ serde( rename( serialize = "updateMods" ) ) ]
149
198
#[ builder( !default ) ]
150
199
pub replacement : Document ,
151
200
201
+ /// The collation to use.
152
202
pub collation : Option < Document > ,
153
203
204
+ /// The index to use. Specify either the index name as a string or the index key pattern. If
205
+ /// specified, then the query system will only consider plans using the hinted index.
154
206
pub hint : Option < Bson > ,
155
207
208
+ /// Whether a new document should be created if no document matches the filter.
209
+ ///
210
+ /// Defaults to false.
156
211
pub upsert : Option < bool > ,
157
212
}
158
213
@@ -162,22 +217,28 @@ impl From<ReplaceOneModel> for WriteModel {
162
217
}
163
218
}
164
219
220
+ /// Deletes a single document.
165
221
#[ skip_serializing_none]
166
222
#[ derive( Clone , Debug , Serialize , TypedBuilder ) ]
167
223
#[ cfg_attr( test, derive( Deserialize ) ) ]
168
224
#[ serde( rename_all = "camelCase" ) ]
169
225
#[ builder( field_defaults( default , setter( into) ) ) ]
170
226
#[ non_exhaustive]
171
227
pub struct DeleteOneModel {
228
+ /// The namespace on which the delete should be performed.
172
229
#[ serde( skip_serializing) ]
173
230
#[ builder( !default ) ]
174
231
pub namespace : Namespace ,
175
232
233
+ /// The filter to use. The first document matching this filter will be deleted.
176
234
#[ builder( !default ) ]
177
235
pub filter : Document ,
178
236
237
+ /// The collation to use.
179
238
pub collation : Option < Document > ,
180
239
240
+ /// The index to use. Specify either the index name as a string or the index key pattern. If
241
+ /// specified, then the query system will only consider plans using the hinted index.
181
242
pub hint : Option < Bson > ,
182
243
}
183
244
@@ -187,21 +248,27 @@ impl From<DeleteOneModel> for WriteModel {
187
248
}
188
249
}
189
250
251
+ /// Deletes multiple documents.
190
252
#[ skip_serializing_none]
191
253
#[ derive( Clone , Debug , Serialize , TypedBuilder ) ]
192
254
#[ cfg_attr( test, derive( Deserialize ) ) ]
193
255
#[ serde( rename_all = "camelCase" ) ]
194
256
#[ builder( field_defaults( default , setter( into) ) ) ]
195
257
#[ non_exhaustive]
196
258
pub struct DeleteManyModel {
259
+ /// The namespace on which the delete should be performed.
197
260
#[ serde( skip_serializing) ]
198
261
#[ builder( !default ) ]
199
262
pub namespace : Namespace ,
200
263
264
+ /// The filter to use. All documents matching this filter will be deleted.
201
265
pub filter : Document ,
202
266
267
+ /// The collation to use.
203
268
pub collation : Option < Document > ,
204
269
270
+ /// The index to use. Specify either the index name as a string or the index key pattern. If
271
+ /// specified, then the query system will only consider plans using the hinted index.
205
272
pub hint : Option < Bson > ,
206
273
}
207
274
@@ -215,6 +282,11 @@ impl<T> Collection<T>
215
282
where
216
283
T : Send + Sync + Serialize ,
217
284
{
285
+ /// Constructs an [`InsertOneModel`] with this collection's namespace by serializing the
286
+ /// provided value into a [`Document`]. Returns an error if serialization fails.
287
+ ///
288
+ /// Note that the returned value must be provided to [`bulk_write`](crate::Client::bulk_write)
289
+ /// for the insert to be performed.
218
290
pub fn insert_one_model ( & self , document : impl Borrow < T > ) -> Result < InsertOneModel > {
219
291
let document = bson:: to_document ( document. borrow ( ) ) ?;
220
292
Ok ( InsertOneModel :: builder ( )
@@ -223,6 +295,11 @@ where
223
295
. build ( ) )
224
296
}
225
297
298
+ /// Constructs a [`ReplaceOneModel`] with this collection's namespace by serializing the
299
+ /// provided value into a [`Document`]. Returns an error if serialization fails.
300
+ ///
301
+ /// Note that the returned value must be provided to [`bulk_write`](crate::Client::bulk_write)
302
+ /// for the replace to be performed.
226
303
pub fn replace_one_model (
227
304
& self ,
228
305
filter : Document ,
0 commit comments