Struct mongod::query::Find[][src]

pub struct Find<C: Collection> { /* fields omitted */ }

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(doc) = res {
        let user: User = User::from_document(doc).unwrap();
        println!("{:?}", user);
    }
}

Implementations

impl<C: Collection> Find<C>[src]

pub fn new() -> Self[src]

Constructs a Find querier.

pub fn allow_disk_use(self, enable: bool) -> Self[src]

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.

pub fn allow_partial_results(self, enable: bool) -> Self[src]

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.

pub fn batch_size(self, size: u32) -> Self[src]

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.

pub fn collation(self, value: Collation) -> Self[src]

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.

pub fn comment(self, value: String) -> Self[src]

Tags the query with an arbitrary string.

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

pub fn cursor_type(self, type: CursorType) -> Self[src]

The type of cursor to return.

pub fn filter<F>(self, filter: F) -> Result<Self, Error> where
    C: AsFilter<F>,
    F: Filter
[src]

The filter to use for the operation.

Errors

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

pub fn hint(self, value: Hint) -> Self[src]

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

pub fn limit(self, value: i64) -> Self[src]

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.

pub fn max(self, document: Document) -> Self[src]

The exclusive upper bound for a specific index.

pub fn max_await_time(self, duration: Duration) -> Self[src]

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.

pub fn max_scan(self, value: i64) -> Self[src]

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.

pub fn max_time(self, duration: Duration) -> Self[src]

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.

pub fn min(self, document: Document) -> Self[src]

The inclusive lower bound for a specific index.

pub fn no_cursor_timeout(self, enable: bool) -> Self[src]

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

pub fn projection(self, document: Document) -> Self[src]

Limits the fields of the document being returned.

pub fn read_concern(self, concern: ReadConcern) -> Self[src]

The read concern to use for this find query.

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

pub fn return_key(self, enable: bool) -> Self[src]

Whether to return only the index keys in the documents.

pub fn selection_criteria(self, criteria: SelectionCriteria) -> Self[src]

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

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

pub fn show_record_id(self, enable: bool) -> Self[src]

Whether to return the record identifier for each document.

pub fn skip(self, value: i64) -> Self[src]

The number of documents to skip before counting.

pub fn sort<F>(self, sort: Sort<F>) -> Self where
    C: AsField<F>,
    F: Field + Into<String>, 
[src]

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

pub async fn query(self, client: &Client) -> Result<Cursor, Error>[src]

Query the database with this querier.

Errors

This method fails if the mongodb encountered an error.

pub fn blocking(self, client: &Client) -> Result<Cursor, Error>[src]

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

impl<C: Clone + Collection> Clone for Find<C>[src]

impl<C: Collection> Default for Find<C>[src]

Auto Trait Implementations

impl<C> !RefUnwindSafe for Find<C>

impl<C> Send for Find<C> where
    C: Send

impl<C> Sync for Find<C> where
    C: Sync

impl<C> Unpin for Find<C> where
    C: Unpin

impl<C> !UnwindSafe for Find<C>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,