pub struct Find<C: Collection> { /* private fields */ }
Expand description
A querier to find documents in a MongoDB collection.
Examples
Find all documents from a collection.
use futures::stream::StreamExt;
use mongod::Collection;
#[derive(Debug, Bson, Mongo)]
#[mongo(collection="users", field, filter, update)]
pub struct User {
name: String,
}
let client = mongod::Client::new();
let mut cursor = mongod::query::Find::<User>::new()
.query(&client)
.await
.unwrap();
while let Some(res) = cursor.next().await {
if let Ok((id, user)) = res {
println!("{} - {:?}", id, user);
}
}
Implementations
sourceimpl<C: Collection> Find<C>
impl<C: Collection> Find<C>
sourcepub fn allow_disk_use(self, enable: bool) -> Self
pub fn allow_disk_use(self, enable: bool) -> Self
Enables writing to temporary files by the server.
When set to true, the find operation can write data to the _tmp subdirectory in the dbPath directory.
sourcepub fn allow_partial_results(self, enable: bool) -> Self
pub fn allow_partial_results(self, enable: bool) -> Self
Enables partial results.
If true, partial results will be returned from a mongodb rather than an error being returned if one or more shards is down.
sourcepub fn batch_size(self, size: u32) -> Self
pub fn batch_size(self, size: u32) -> Self
The number of documents the server should return per cursor batch.
Notes
This does not have any affect on the documents that are returned by a cursor, only the number of documents kept in memory at a given time (and by extension, the number of round trips needed to return the entire set of documents returned by the query.
sourcepub fn collation(self, value: Collation) -> Self
pub fn collation(self, value: Collation) -> Self
The collation to use for the operation.
Collation allows users to specify language-specific rules for string comparison, such as rules for lettercase and accent marks.
sourcepub fn comment(self, value: String) -> Self
pub fn comment(self, value: String) -> Self
Tags the query with an arbitrary string.
Used to help trace the operation through the database profiler, currentOp and logs.
sourcepub fn cursor_type(self, type: CursorType) -> Self
pub fn cursor_type(self, type: CursorType) -> Self
The type of cursor to return.
sourcepub fn filter<F>(self, filter: F) -> Result<Self, Error>where
C: AsFilter<F>,
F: Filter,
pub fn filter<F>(self, filter: F) -> Result<Self, Error>where
C: AsFilter<F>,
F: Filter,
The filter to use for the operation.
Errors
This method errors if the filter could not be converted into a BSON Document
.
sourcepub fn hint(self, value: Hint) -> Self
pub fn hint(self, value: Hint) -> Self
A document or string that specifies the index to use to support the query predicate.
sourcepub fn limit(self, value: i64) -> Self
pub fn limit(self, value: i64) -> Self
The maximum number of documents to query.
If a negative number is specified, the documents will be returned in a single batch limited in number by the positive value of the specified limit.
sourcepub fn max_await_time(self, duration: Duration) -> Self
pub fn max_await_time(self, duration: Duration) -> Self
The maximum amount of time for the server to wait on new documents to satisfy a tailable cursor query.
If the cursor is not tailable, this option is ignored.
sourcepub fn max_scan(self, value: u64) -> Self
pub fn max_scan(self, value: u64) -> Self
Maximum number of documents or index keys to scan when executing the query.
Notes
This option is deprecated starting in MongoDB version 4.0 and removed in MongoDB 4.2. Use the max_time option instead.
sourcepub fn max_time(self, duration: Duration) -> Self
pub fn max_time(self, duration: Duration) -> Self
The maximum amount of time to allow the query to run.
This options maps to the maxTimeMS MongoDB query option, so the duration will be sent across the wire as an integer number of milliseconds.
sourcepub fn no_cursor_timeout(self, enable: bool) -> Self
pub fn no_cursor_timeout(self, enable: bool) -> Self
Whether the server should close the cursor after a period of inactivity.
sourcepub fn projection(self, document: Document) -> Self
pub fn projection(self, document: Document) -> Self
Limits the fields of the document being returned.
sourcepub fn read_concern(self, concern: ReadConcern) -> Self
pub fn read_concern(self, concern: ReadConcern) -> Self
The read concern to use for this find query.
If none specified, the default set on the collection will be used.
sourcepub fn return_key(self, enable: bool) -> Self
pub fn return_key(self, enable: bool) -> Self
Whether to return only the index keys in the documents.
sourcepub fn selection_criteria(self, criteria: SelectionCriteria) -> Self
pub fn selection_criteria(self, criteria: SelectionCriteria) -> Self
The criteria used to select a server for this find query.
If none specified, the default set on the collection will be used.
sourcepub fn show_record_id(self, enable: bool) -> Self
pub fn show_record_id(self, enable: bool) -> Self
Whether to return the record identifier for each document.
sourcepub fn sort<F>(self, sort: Sort<F>) -> Selfwhere
C: AsField<F>,
F: Field + Into<String>,
pub fn sort<F>(self, sort: Sort<F>) -> Selfwhere
C: AsField<F>,
F: Field + Into<String>,
The order in which to sort the documents of the operation.