[][src]Struct mongodb::coll::Collection

pub struct Collection {
    pub db: Database,
    pub namespace: String,
    // some fields omitted
}

Interfaces with a MongoDB collection.

Fields

db: Database

A reference to the database that spawned this collection.

namespace: String

The namespace of this collection, formatted as db_name.coll_name.

Methods

impl Collection[src]

pub fn new(
    db: Database,
    name: &str,
    create: bool,
    read_preference: Option<ReadPreference>,
    write_concern: Option<WriteConcern>
) -> Collection
[src]

Creates a collection representation with optional read and write controls.

If create is specified, the collection will be explicitly created in the database.

pub fn get_req_id(&self) -> i32[src]

Returns a unique operational request id.

pub fn name(&self) -> String[src]

Extracts the collection name from the namespace. If the namespace is invalid, this method will panic.

pub fn drop(&self) -> Result<()>[src]

Permanently deletes the collection from the database.

pub fn aggregate(
    &self,
    pipeline: Vec<Document>,
    options: Option<AggregateOptions>
) -> Result<Cursor>
[src]

Runs an aggregation framework pipeline.

pub fn count(
    &self,
    filter: Option<Document>,
    options: Option<CountOptions>
) -> Result<i64>
[src]

Gets the number of documents matching the filter.

pub fn distinct(
    &self,
    field_name: &str,
    filter: Option<Document>,
    options: Option<DistinctOptions>
) -> Result<Vec<Bson>>
[src]

Finds the distinct values for a specified field across a single collection.

pub fn find(
    &self,
    filter: Option<Document>,
    options: Option<FindOptions>
) -> Result<Cursor>
[src]

Returns a list of documents within the collection that match the filter.

pub fn find_one(
    &self,
    filter: Option<Document>,
    options: Option<FindOptions>
) -> Result<Option<Document>>
[src]

Returns the first document within the collection that matches the filter, or None.

pub fn find_one_with_command_type(
    &self,
    filter: Option<Document>,
    options: Option<FindOptions>,
    cmd_type: CommandType
) -> Result<Option<Document>>
[src]

pub fn find_one_and_delete(
    &self,
    filter: Document,
    options: Option<FindOneAndDeleteOptions>
) -> Result<Option<Document>>
[src]

Finds a single document and deletes it, returning the original.

pub fn find_one_and_replace(
    &self,
    filter: Document,
    replacement: Document,
    options: Option<FindOneAndUpdateOptions>
) -> Result<Option<Document>>
[src]

Finds a single document and replaces it, returning either the original or replaced document.

pub fn find_one_and_update(
    &self,
    filter: Document,
    update: Document,
    options: Option<FindOneAndUpdateOptions>
) -> Result<Option<Document>>
[src]

Finds a single document and updates it, returning either the original or updated document.

pub fn bulk_write(
    &self,
    requests: Vec<WriteModel>,
    ordered: bool
) -> BulkWriteResult
[src]

Sends a batch of writes to the server at the same time.

pub fn insert_one(
    &self,
    doc: Document,
    write_concern: Option<WriteConcern>
) -> Result<InsertOneResult>
[src]

Inserts the provided document. If the document is missing an identifier, the driver should generate one.

pub fn insert_many(
    &self,
    docs: Vec<Document>,
    options: Option<InsertManyOptions>
) -> Result<InsertManyResult>
[src]

Inserts the provided documents. If any documents are missing an identifier, the driver should generate them.

pub fn delete_one(
    &self,
    filter: Document,
    write_concern: Option<WriteConcern>
) -> Result<DeleteResult>
[src]

Deletes a single document.

pub fn delete_many(
    &self,
    filter: Document,
    write_concern: Option<WriteConcern>
) -> Result<DeleteResult>
[src]

Deletes multiple documents.

pub fn replace_one(
    &self,
    filter: Document,
    replacement: Document,
    options: Option<ReplaceOptions>
) -> Result<UpdateResult>
[src]

Replaces a single document.

pub fn update_one(
    &self,
    filter: Document,
    update: Document,
    options: Option<UpdateOptions>
) -> Result<UpdateResult>
[src]

Updates a single document.

pub fn update_many(
    &self,
    filter: Document,
    update: Document,
    options: Option<UpdateOptions>
) -> Result<UpdateResult>
[src]

Updates multiple documents.

pub fn create_index(
    &self,
    keys: Document,
    options: Option<IndexOptions>
) -> Result<String>
[src]

Create a single index.

pub fn create_index_model(&self, model: IndexModel) -> Result<String>[src]

Create a single index with an IndexModel.

pub fn create_indexes(&self, models: Vec<IndexModel>) -> Result<Vec<String>>[src]

Create multiple indexes.

pub fn drop_index(
    &self,
    keys: Document,
    options: Option<IndexOptions>
) -> Result<()>
[src]

Drop an index.

pub fn drop_index_string(&self, name: String) -> Result<()>[src]

Drop an index by name.

pub fn drop_index_model(&self, model: IndexModel) -> Result<()>[src]

Drop an index by IndexModel.

pub fn drop_indexes(&self) -> Result<()>[src]

Drop all indexes in the collection.

pub fn list_indexes(&self) -> Result<Cursor>[src]

List all indexes in the collection.

pub fn list_index_models(
    &self
) -> Result<impl Iterator<Item = Result<IndexModel>>>
[src]

List all indexes in the collection as serialized IndexModels.

This is the same as list_indexes, and still uses a Cursor under the hood. The elements are serialized as IndexModels as they are received.

Trait Implementations

impl Debug for Collection[src]

Auto Trait Implementations

Blanket Implementations

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

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

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<T> BorrowMut<T> for T where
    T: ?Sized
[src]

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

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

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

impl<T> Same<T> for T

type Output = T

Should always be Self