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

Constructs a Find querier.

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.

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.

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.

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.

Tags the query with an arbitrary string.

Used to help trace the operation through the database profiler, currentOp and logs.

The type of cursor to return.

The filter to use for the operation.

Errors

This method errors if the filter could not be converted into a BSON Document.

A document or string that specifies the index to use to support the query predicate.

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.

The exclusive upper bound for a specific index.

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.

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.

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.

The inclusive lower bound for a specific index.

Whether the server should close the cursor after a period of inactivity.

Limits the fields of the document being returned.

The read concern to use for this find query.

If none specified, the default set on the collection will be used.

Whether to return only the index keys in the documents.

The criteria used to select a server for this find query.

If none specified, the default set on the collection will be used.

Whether to return the record identifier for each document.

The number of documents to skip before counting.

The order in which to sort the documents of the operation.

Query the database with this querier.

Errors

This method fails if the mongodb encountered an error.

Query the database with this querier in a blocking context.

Optional

This requires the optional blocking feature to be enabled.

Errors

This method fails if the mongodb encountered an error.

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.