mongodb 3.6.0

The official MongoDB driver for Rust
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
//! This file was autogenerated.  Do not manually edit.
use super::*;
use mongodb_internal_macros::{export_doc, options_doc};
///`autocomplete` Atlas Search operator.  Construct with [`autocomplete`](autocomplete()).
pub struct Autocomplete;
/**The autocomplete operator performs a search for a word or phrase that
contains a sequence of characters from an incomplete input string. The
fields that you intend to query with the autocomplete operator must be
indexed with the autocomplete data type in the collection's index definition.
*/
///
///For more details, see the [autocomplete operator reference](https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/).
#[options_doc(autocomplete, "into_stage")]
pub fn autocomplete(
    path: impl StringOrArray,
    query: impl StringOrArray,
) -> SearchOperator<Autocomplete> {
    SearchOperator::new(
        "autocomplete",
        doc! {
            "path" : path.to_bson(), "query" : query.to_bson(),
        },
    )
}
#[export_doc(autocomplete)]
impl SearchOperator<Autocomplete> {
    #[allow(missing_docs)]
    pub fn token_order(mut self, token_order: TokenOrder) -> Self {
        self.spec.insert("tokenOrder", token_order.name());
        self
    }
    #[allow(missing_docs)]
    pub fn fuzzy(mut self, fuzzy: Document) -> Self {
        self.spec.insert("fuzzy", fuzzy);
        self
    }
    #[allow(missing_docs)]
    pub fn score(mut self, score: Document) -> Self {
        self.spec.insert("score", score);
        self
    }
}
///`compound` Atlas Search operator.  Construct with [`compound`](compound()).
pub struct Compound;
/**The compound operator combines two or more operators into a single query.
Each element of a compound query is called a clause, and each clause
consists of one or more sub-queries.
*/
///
///For more details, see the [compound operator reference](https://www.mongodb.com/docs/atlas/atlas-search/compound/).
#[options_doc(compound, "into_stage")]
pub fn compound() -> SearchOperator<Compound> {
    SearchOperator::new("compound", doc! {})
}
#[export_doc(compound)]
impl SearchOperator<Compound> {
    #[allow(missing_docs)]
    pub fn must(mut self, must: impl IntoIterator<Item = impl SearchOperatorParam>) -> Self {
        self.spec.insert(
            "must",
            must.into_iter().map(|o| o.to_bson()).collect::<Vec<_>>(),
        );
        self
    }
    #[allow(missing_docs)]
    pub fn must_not(
        mut self,
        must_not: impl IntoIterator<Item = impl SearchOperatorParam>,
    ) -> Self {
        self.spec.insert(
            "mustNot",
            must_not
                .into_iter()
                .map(|o| o.to_bson())
                .collect::<Vec<_>>(),
        );
        self
    }
    #[allow(missing_docs)]
    pub fn should(mut self, should: impl IntoIterator<Item = impl SearchOperatorParam>) -> Self {
        self.spec.insert(
            "should",
            should.into_iter().map(|o| o.to_bson()).collect::<Vec<_>>(),
        );
        self
    }
    #[allow(missing_docs)]
    pub fn filter(mut self, filter: impl IntoIterator<Item = impl SearchOperatorParam>) -> Self {
        self.spec.insert(
            "filter",
            filter.into_iter().map(|o| o.to_bson()).collect::<Vec<_>>(),
        );
        self
    }
    #[allow(missing_docs)]
    pub fn minimum_should_match(mut self, minimum_should_match: i32) -> Self {
        self.spec.insert("minimumShouldMatch", minimum_should_match);
        self
    }
    #[allow(missing_docs)]
    pub fn score(mut self, score: Document) -> Self {
        self.spec.insert("score", score);
        self
    }
}
///`embeddedDocument` Atlas Search operator.  Construct with
/// [`embedded_document`](embedded_document()).
pub struct EmbeddedDocument;
/**The embeddedDocument operator is similar to $elemMatch operator.
It constrains multiple query predicates to be satisfied from a single
element of an array of embedded documents. embeddedDocument can be used only
for queries over fields of the embeddedDocuments
*/
///
///For more details, see the [embeddedDocument operator reference](https://www.mongodb.com/docs/atlas/atlas-search/embedded-document/).
#[options_doc(embedded_document, "into_stage")]
pub fn embedded_document(
    path: impl StringOrArray,
    operator: impl SearchOperatorParam,
) -> SearchOperator<EmbeddedDocument> {
    SearchOperator::new(
        "embeddedDocument",
        doc! {
            "path" : path.to_bson(), "operator" : operator.to_bson(),
        },
    )
}
#[export_doc(embedded_document)]
impl SearchOperator<EmbeddedDocument> {
    #[allow(missing_docs)]
    pub fn score(mut self, score: Document) -> Self {
        self.spec.insert("score", score);
        self
    }
}
///`equals` Atlas Search operator.  Construct with [`equals`](equals()).
pub struct Equals;
/**The equals operator checks whether a field matches a value you specify.
 * */
///
///For more details, see the [equals operator reference](https://www.mongodb.com/docs/atlas/atlas-search/equals/).
#[options_doc(equals, "into_stage")]
pub fn equals(path: impl StringOrArray, value: impl Into<Bson>) -> SearchOperator<Equals> {
    SearchOperator::new(
        "equals",
        doc! {
            "path" : path.to_bson(), "value" : value.into(),
        },
    )
}
#[export_doc(equals)]
impl SearchOperator<Equals> {
    #[allow(missing_docs)]
    pub fn score(mut self, score: Document) -> Self {
        self.spec.insert("score", score);
        self
    }
}
///`exists` Atlas Search operator.  Construct with [`exists`](exists()).
pub struct Exists;
/**The exists operator tests if a path to a specified indexed field name exists in a document.
 * */
///
///For more details, see the [exists operator reference](https://www.mongodb.com/docs/atlas/atlas-search/exists/).
#[options_doc(exists, "into_stage")]
pub fn exists(path: impl StringOrArray) -> SearchOperator<Exists> {
    SearchOperator::new(
        "exists",
        doc! {
            "path" : path.to_bson(),
        },
    )
}
#[export_doc(exists)]
impl SearchOperator<Exists> {
    #[allow(missing_docs)]
    pub fn score(mut self, score: Document) -> Self {
        self.spec.insert("score", score);
        self
    }
}
///`facet` Atlas Search operator.  Construct with [`facet`](facet()).
pub struct Facet;
/**The facet collector groups results by values or ranges in the specified
faceted fields and returns the count for each of those groups.
*/
///
///For more details, see the [facet operator reference](https://www.mongodb.com/docs/atlas/atlas-search/facet/).
#[options_doc(facet, "into_stage")]
pub fn facet(facets: Document) -> SearchOperator<Facet> {
    SearchOperator::new(
        "facet",
        doc! {
            "facets" : facets,
        },
    )
}
#[export_doc(facet)]
impl SearchOperator<Facet> {
    #[allow(missing_docs)]
    pub fn operator(mut self, operator: impl SearchOperatorParam) -> Self {
        self.spec.insert("operator", operator.to_bson());
        self
    }
}
///`geoShape` Atlas Search operator.  Construct with [`geo_shape`](geo_shape()).
pub struct GeoShape;
/**The geoShape operator supports querying shapes with a relation to a given
geometry if indexShapes is set to true in the index definition.
*/
///
///For more details, see the [geoShape operator reference](https://www.mongodb.com/docs/atlas/atlas-search/geoShape/).
#[options_doc(geo_shape, "into_stage")]
pub fn geo_shape(
    path: impl StringOrArray,
    relation: Relation,
    geometry: Document,
) -> SearchOperator<GeoShape> {
    SearchOperator::new(
        "geoShape",
        doc! {
            "path" : path.to_bson(), "relation" : relation.name(), "geometry" : geometry,
        },
    )
}
#[export_doc(geo_shape)]
impl SearchOperator<GeoShape> {
    #[allow(missing_docs)]
    pub fn score(mut self, score: Document) -> Self {
        self.spec.insert("score", score);
        self
    }
}
///`geoWithin` Atlas Search operator.  Construct with [`geo_within`](geo_within()).
pub struct GeoWithin;
/**The geoWithin operator supports querying geographic points within a given
geometry. Only points are returned, even if indexShapes value is true in
the index definition.
*/
///
///For more details, see the [geoWithin operator reference](https://www.mongodb.com/docs/atlas/atlas-search/geoWithin/).
#[options_doc(geo_within, "into_stage")]
pub fn geo_within(path: impl StringOrArray) -> SearchOperator<GeoWithin> {
    SearchOperator::new(
        "geoWithin",
        doc! {
            "path" : path.to_bson(),
        },
    )
}
#[export_doc(geo_within)]
impl SearchOperator<GeoWithin> {
    #[allow(missing_docs)]
    pub fn geo_box(mut self, geo_box: Document) -> Self {
        self.spec.insert("box", geo_box);
        self
    }
    #[allow(missing_docs)]
    pub fn circle(mut self, circle: Document) -> Self {
        self.spec.insert("circle", circle);
        self
    }
    #[allow(missing_docs)]
    pub fn geometry(mut self, geometry: Document) -> Self {
        self.spec.insert("geometry", geometry);
        self
    }
    #[allow(missing_docs)]
    pub fn score(mut self, score: Document) -> Self {
        self.spec.insert("score", score);
        self
    }
}
///`in` Atlas Search operator.  Construct with [`search_in`](search_in()).
pub struct SearchIn;
/**The in operator performs a search for an array of BSON values in a field.
 * */
///
///For more details, see the [in operator reference](https://www.mongodb.com/docs/atlas/atlas-search/in/).
#[options_doc(search_in, "into_stage")]
pub fn search_in(path: impl StringOrArray, value: impl Into<Bson>) -> SearchOperator<SearchIn> {
    SearchOperator::new(
        "in",
        doc! {
            "path" : path.to_bson(), "value" : value.into(),
        },
    )
}
#[export_doc(search_in)]
impl SearchOperator<SearchIn> {
    #[allow(missing_docs)]
    pub fn score(mut self, score: Document) -> Self {
        self.spec.insert("score", score);
        self
    }
}
///`moreLikeThis` Atlas Search operator.  Construct with [`more_like_this`](more_like_this()).
pub struct MoreLikeThis;
/**The moreLikeThis operator returns documents similar to input documents.
The moreLikeThis operator allows you to build features for your applications
that display similar or alternative results based on one or more given documents.
*/
///
///For more details, see the [moreLikeThis operator reference](https://www.mongodb.com/docs/atlas/atlas-search/moreLikeThis/).
#[options_doc(more_like_this, "into_stage")]
pub fn more_like_this(like: impl DocumentOrArray) -> SearchOperator<MoreLikeThis> {
    SearchOperator::new(
        "moreLikeThis",
        doc! {
            "like" : like.to_bson(),
        },
    )
}
#[export_doc(more_like_this)]
impl SearchOperator<MoreLikeThis> {
    #[allow(missing_docs)]
    pub fn score(mut self, score: Document) -> Self {
        self.spec.insert("score", score);
        self
    }
}
///`near` Atlas Search operator.  Construct with [`near`](near()).
pub struct Near;
/**The near operator supports querying and scoring numeric, date, and GeoJSON point values.
 * */
///
///For more details, see the [near operator reference](https://www.mongodb.com/docs/atlas/atlas-search/near/).
#[options_doc(near, "into_stage")]
pub fn near(
    path: impl StringOrArray,
    origin: impl NearOrigin,
    pivot: impl BsonNumber,
) -> SearchOperator<Near> {
    SearchOperator::new(
        "near",
        doc! {
            "path" : path.to_bson(), "origin" : origin.to_bson(), "pivot" : pivot
            .to_bson(),
        },
    )
}
#[export_doc(near)]
impl SearchOperator<Near> {
    #[allow(missing_docs)]
    pub fn score(mut self, score: Document) -> Self {
        self.spec.insert("score", score);
        self
    }
}
///`phrase` Atlas Search operator.  Construct with [`phrase`](phrase()).
pub struct Phrase;
/**The phrase operator performs search for documents containing an ordered sequence of terms
 * using the analyzer specified in the index configuration.
 * */
///
///For more details, see the [phrase operator reference](https://www.mongodb.com/docs/atlas/atlas-search/phrase/).
#[options_doc(phrase, "into_stage")]
pub fn phrase(path: impl StringOrArray, query: impl StringOrArray) -> SearchOperator<Phrase> {
    SearchOperator::new(
        "phrase",
        doc! {
            "path" : path.to_bson(), "query" : query.to_bson(),
        },
    )
}
#[export_doc(phrase)]
impl SearchOperator<Phrase> {
    #[allow(missing_docs)]
    pub fn slop(mut self, slop: i32) -> Self {
        self.spec.insert("slop", slop);
        self
    }
    #[allow(missing_docs)]
    pub fn synonyms(mut self, synonyms: impl AsRef<str>) -> Self {
        self.spec.insert("synonyms", synonyms.as_ref());
        self
    }
    #[allow(missing_docs)]
    pub fn score(mut self, score: Document) -> Self {
        self.spec.insert("score", score);
        self
    }
}
///`queryString` Atlas Search operator.  Construct with [`query_string`](query_string()).
pub struct QueryString;
///
///
///For more details, see the [queryString operator reference](https://www.mongodb.com/docs/atlas/atlas-search/queryString/).
#[options_doc(query_string, "into_stage")]
pub fn query_string(
    default_path: impl StringOrArray,
    query: impl AsRef<str>,
) -> SearchOperator<QueryString> {
    SearchOperator::new(
        "queryString",
        doc! {
            "defaultPath" : default_path.to_bson(), "query" : query.as_ref(),
        },
    )
}
#[export_doc(query_string)]
impl SearchOperator<QueryString> {}
///`range` Atlas Search operator.  Construct with [`range`](range()).
pub struct Range;
/**The range operator supports querying and scoring numeric, date, and string values.
You can use this operator to find results that are within a given numeric, date, objectId, or letter (from the English alphabet) range.
*/
///
///For more details, see the [range operator reference](https://www.mongodb.com/docs/atlas/atlas-search/range/).
#[options_doc(range, "into_stage")]
pub fn range(path: impl StringOrArray) -> SearchOperator<Range> {
    SearchOperator::new(
        "range",
        doc! {
            "path" : path.to_bson(),
        },
    )
}
#[export_doc(range)]
impl SearchOperator<Range> {
    #[allow(missing_docs)]
    pub fn gt(mut self, gt: impl RangeValue) -> Self {
        self.spec.insert("gt", gt.to_bson());
        self
    }
    #[allow(missing_docs)]
    pub fn gte(mut self, gte: impl RangeValue) -> Self {
        self.spec.insert("gte", gte.to_bson());
        self
    }
    #[allow(missing_docs)]
    pub fn lt(mut self, lt: impl RangeValue) -> Self {
        self.spec.insert("lt", lt.to_bson());
        self
    }
    #[allow(missing_docs)]
    pub fn lte(mut self, lte: impl RangeValue) -> Self {
        self.spec.insert("lte", lte.to_bson());
        self
    }
    #[allow(missing_docs)]
    pub fn score(mut self, score: Document) -> Self {
        self.spec.insert("score", score);
        self
    }
}
///`regex` Atlas Search operator.  Construct with [`regex`](regex()).
pub struct Regex;
/**regex interprets the query field as a regular expression.
regex is a term-level operator, meaning that the query field isn't analyzed.
*/
///
///For more details, see the [regex operator reference](https://www.mongodb.com/docs/atlas/atlas-search/regex/).
#[options_doc(regex, "into_stage")]
pub fn regex(path: impl StringOrArray, query: impl AsRef<str>) -> SearchOperator<Regex> {
    SearchOperator::new(
        "regex",
        doc! {
            "path" : path.to_bson(), "query" : query.as_ref(),
        },
    )
}
#[export_doc(regex)]
impl SearchOperator<Regex> {
    #[allow(missing_docs)]
    pub fn allow_analyzed_field(mut self, allow_analyzed_field: bool) -> Self {
        self.spec.insert("allowAnalyzedField", allow_analyzed_field);
        self
    }
    #[allow(missing_docs)]
    pub fn score(mut self, score: Document) -> Self {
        self.spec.insert("score", score);
        self
    }
}
///`text` Atlas Search operator.  Construct with [`text`](text()).
pub struct Text;
/**The text operator performs a full-text search using the analyzer that you specify in the index configuration.
If you omit an analyzer, the text operator uses the default standard analyzer.
*/
///
///For more details, see the [text operator reference](https://www.mongodb.com/docs/atlas/atlas-search/text/).
#[options_doc(text, "into_stage")]
pub fn text(path: impl StringOrArray, query: impl StringOrArray) -> SearchOperator<Text> {
    SearchOperator::new(
        "text",
        doc! {
            "path" : path.to_bson(), "query" : query.to_bson(),
        },
    )
}
#[export_doc(text)]
impl SearchOperator<Text> {
    #[allow(missing_docs)]
    pub fn fuzzy(mut self, fuzzy: Document) -> Self {
        self.spec.insert("fuzzy", fuzzy);
        self
    }
    #[allow(missing_docs)]
    pub fn match_criteria(mut self, match_criteria: MatchCriteria) -> Self {
        self.spec.insert("matchCriteria", match_criteria.name());
        self
    }
    #[allow(missing_docs)]
    pub fn synonyms(mut self, synonyms: impl AsRef<str>) -> Self {
        self.spec.insert("synonyms", synonyms.as_ref());
        self
    }
    #[allow(missing_docs)]
    pub fn score(mut self, score: Document) -> Self {
        self.spec.insert("score", score);
        self
    }
}
///`wildcard` Atlas Search operator.  Construct with [`wildcard`](wildcard()).
pub struct Wildcard;
/**The wildcard operator enables queries which use special characters in the search string that
 * can match any character.
 * */
///
///For more details, see the [wildcard operator reference](https://www.mongodb.com/docs/atlas/atlas-search/wildcard/).
#[options_doc(wildcard, "into_stage")]
pub fn wildcard(path: impl StringOrArray, query: impl AsRef<str>) -> SearchOperator<Wildcard> {
    SearchOperator::new(
        "wildcard",
        doc! {
            "path" : path.to_bson(), "query" : query.as_ref(),
        },
    )
}
#[export_doc(wildcard)]
impl SearchOperator<Wildcard> {
    #[allow(missing_docs)]
    pub fn allow_analyzed_field(mut self, allow_analyzed_field: bool) -> Self {
        self.spec.insert("allowAnalyzedField", allow_analyzed_field);
        self
    }
    #[allow(missing_docs)]
    pub fn score(mut self, score: Document) -> Self {
        self.spec.insert("score", score);
        self
    }
}