Struct mongodb::Collection[][src]

pub struct Collection<T = Document> where
    T: Serialize + DeserializeOwned + Unpin + Debug
{ /* fields omitted */ }
Expand description

Collection is the client-side abstraction of a MongoDB Collection. It can be used to perform collection-level operations such as CRUD operations. A Collection can be obtained through a Database by calling either Database::collection or Database::collection_with_options.

Collection uses std::sync::Arc internally, so it can safely be shared across threads or async tasks. For example:

let coll = client.database("items").collection("in_stock");

for i in 0..5 {
    let coll_ref = coll.clone();

    task::spawn(async move {
        // Perform operations with `coll_ref`. For example:
        coll_ref.insert_one(doc! { "x": i }, None).await;
    });
}

Implementations

Gets a clone of the Collection with a different type U.

Gets the name of the Collection.

Gets the namespace of the Collection.

The namespace of a MongoDB collection is the concatenation of the name of the database containing it, the ‘.’ character, and the name of the collection itself. For example, if a collection named “bar” is created in a database named “foo”, the namespace of the collection is “foo.bar”.

Gets the selection criteria of the Collection.

Gets the read concern of the Collection.

Gets the write concern of the Collection.

Drops the collection, deleting all data and indexes stored in it.

Runs an aggregation operation.

See the documentation here for more information on aggregations.

Estimates the number of documents in the collection using collection metadata.

Gets the number of documents matching filter.

Note that using Collection::estimated_document_count is recommended instead of this method is most cases.

Deletes all documents stored in the collection matching query.

Deletes up to one document found matching query.

This operation will retry once upon failure if the connection and encountered error support retryability. See the documentation here for more information on retryable writes.

Finds the distinct values of the field specified by field_name across the collection.

Finds the documents in the collection matching filter.

Finds a single document in the collection matching filter.

Atomically finds up to one document in the collection matching filter and deletes it.

This operation will retry once upon failure if the connection and encountered error support retryability. See the documentation here for more information on retryable writes.

Atomically finds up to one document in the collection matching filter and replaces it with replacement.

This operation will retry once upon failure if the connection and encountered error support retryability. See the documentation here for more information on retryable writes.

Atomically finds up to one document in the collection matching filter and updates it. Both Document and Vec<Document> implement Into<UpdateModifications>, so either can be passed in place of constructing the enum case. Note: pipeline updates are only supported in MongoDB 4.2+.

This operation will retry once upon failure if the connection and encountered error support retryability. See the documentation here for more information on retryable writes.

Inserts the data in docs into the collection.

This operation will retry once upon failure if the connection and encountered error support retryability. See the documentation here for more information on retryable writes.

Inserts doc into the collection.

This operation will retry once upon failure if the connection and encountered error support retryability. See the documentation here for more information on retryable writes.

Replaces up to one document matching query in the collection with replacement.

This operation will retry once upon failure if the connection and encountered error support retryability. See the documentation here for more information on retryable writes.

Updates all documents matching query in the collection.

Both Document and Vec<Document> implement Into<UpdateModifications>, so either can be passed in place of constructing the enum case. Note: pipeline updates are only supported in MongoDB 4.2+. See the official MongoDB documentation for more information on specifying updates.

Updates up to one document matching query in the collection.

Both Document and Vec<Document> implement Into<UpdateModifications>, so either can be passed in place of constructing the enum case. Note: pipeline updates are only supported in MongoDB 4.2+. See the official MongoDB documentation for more information on specifying updates.

This operation will retry once upon failure if the connection and encountered error support retryability. See the documentation here for more information on retryable writes.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. 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

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more