Struct mongodb::coll::Collection
[−]
[src]
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]
fn new(
db: Database,
name: &str,
create: bool,
read_preference: Option<ReadPreference>,
write_concern: Option<WriteConcern>
) -> Collection
db: Database,
name: &str,
create: bool,
read_preference: Option<ReadPreference>,
write_concern: Option<WriteConcern>
) -> Collection
Creates a collection representation with optional read and write controls.
If create
is specified, the collection will be explicitly created in the database.
fn get_req_id(&self) -> i32
Returns a unique operational request id.
fn name(&self) -> String
Extracts the collection name from the namespace. If the namespace is invalid, this method will panic.
fn drop(&self) -> Result<()>
Permanently deletes the collection from the database.
fn aggregate(
&self,
pipeline: Vec<Document>,
options: Option<AggregateOptions>
) -> Result<Cursor>
&self,
pipeline: Vec<Document>,
options: Option<AggregateOptions>
) -> Result<Cursor>
Runs an aggregation framework pipeline.
fn count(
&self,
filter: Option<Document>,
options: Option<CountOptions>
) -> Result<i64>
&self,
filter: Option<Document>,
options: Option<CountOptions>
) -> Result<i64>
Gets the number of documents matching the filter.
fn distinct(
&self,
field_name: &str,
filter: Option<Document>,
options: Option<DistinctOptions>
) -> Result<Vec<Bson>>
&self,
field_name: &str,
filter: Option<Document>,
options: Option<DistinctOptions>
) -> Result<Vec<Bson>>
Finds the distinct values for a specified field across a single collection.
fn find(
&self,
filter: Option<Document>,
options: Option<FindOptions>
) -> Result<Cursor>
&self,
filter: Option<Document>,
options: Option<FindOptions>
) -> Result<Cursor>
Returns a list of documents within the collection that match the filter.
fn find_one(
&self,
filter: Option<Document>,
options: Option<FindOptions>
) -> Result<Option<Document>>
&self,
filter: Option<Document>,
options: Option<FindOptions>
) -> Result<Option<Document>>
Returns the first document within the collection that matches the filter, or None.
fn find_one_with_command_type(
&self,
filter: Option<Document>,
options: Option<FindOptions>,
cmd_type: CommandType
) -> Result<Option<Document>>
&self,
filter: Option<Document>,
options: Option<FindOptions>,
cmd_type: CommandType
) -> Result<Option<Document>>
fn find_one_and_delete(
&self,
filter: Document,
options: Option<FindOneAndDeleteOptions>
) -> Result<Option<Document>>
&self,
filter: Document,
options: Option<FindOneAndDeleteOptions>
) -> Result<Option<Document>>
Finds a single document and deletes it, returning the original.
fn find_one_and_replace(
&self,
filter: Document,
replacement: Document,
options: Option<FindOneAndUpdateOptions>
) -> Result<Option<Document>>
&self,
filter: Document,
replacement: Document,
options: Option<FindOneAndUpdateOptions>
) -> Result<Option<Document>>
Finds a single document and replaces it, returning either the original or replaced document.
fn find_one_and_update(
&self,
filter: Document,
update: Document,
options: Option<FindOneAndUpdateOptions>
) -> Result<Option<Document>>
&self,
filter: Document,
update: Document,
options: Option<FindOneAndUpdateOptions>
) -> Result<Option<Document>>
Finds a single document and updates it, returning either the original or updated document.
fn bulk_write(
&self,
requests: Vec<WriteModel>,
ordered: bool
) -> BulkWriteResult
&self,
requests: Vec<WriteModel>,
ordered: bool
) -> BulkWriteResult
Sends a batch of writes to the server at the same time.
fn insert_one(
&self,
doc: Document,
write_concern: Option<WriteConcern>
) -> Result<InsertOneResult>
&self,
doc: Document,
write_concern: Option<WriteConcern>
) -> Result<InsertOneResult>
Inserts the provided document. If the document is missing an identifier, the driver should generate one.
fn insert_many(
&self,
docs: Vec<Document>,
options: Option<InsertManyOptions>
) -> Result<InsertManyResult>
&self,
docs: Vec<Document>,
options: Option<InsertManyOptions>
) -> Result<InsertManyResult>
Inserts the provided documents. If any documents are missing an identifier, the driver should generate them.
fn delete_one(
&self,
filter: Document,
write_concern: Option<WriteConcern>
) -> Result<DeleteResult>
&self,
filter: Document,
write_concern: Option<WriteConcern>
) -> Result<DeleteResult>
Deletes a single document.
fn delete_many(
&self,
filter: Document,
write_concern: Option<WriteConcern>
) -> Result<DeleteResult>
&self,
filter: Document,
write_concern: Option<WriteConcern>
) -> Result<DeleteResult>
Deletes multiple documents.
fn replace_one(
&self,
filter: Document,
replacement: Document,
options: Option<ReplaceOptions>
) -> Result<UpdateResult>
&self,
filter: Document,
replacement: Document,
options: Option<ReplaceOptions>
) -> Result<UpdateResult>
Replaces a single document.
fn update_one(
&self,
filter: Document,
update: Document,
options: Option<UpdateOptions>
) -> Result<UpdateResult>
&self,
filter: Document,
update: Document,
options: Option<UpdateOptions>
) -> Result<UpdateResult>
Updates a single document.
fn update_many(
&self,
filter: Document,
update: Document,
options: Option<UpdateOptions>
) -> Result<UpdateResult>
&self,
filter: Document,
update: Document,
options: Option<UpdateOptions>
) -> Result<UpdateResult>
Updates multiple documents.
fn create_index(
&self,
keys: Document,
options: Option<IndexOptions>
) -> Result<String>
&self,
keys: Document,
options: Option<IndexOptions>
) -> Result<String>
Create a single index.
fn create_index_model(&self, model: IndexModel) -> Result<String>
Create a single index with an IndexModel.
fn create_indexes(&self, models: Vec<IndexModel>) -> Result<Vec<String>>
Create multiple indexes.
fn drop_index(
&self,
keys: Document,
options: Option<IndexOptions>
) -> Result<()>
&self,
keys: Document,
options: Option<IndexOptions>
) -> Result<()>
Drop an index.
fn drop_index_string(&self, name: String) -> Result<()>
Drop an index by name.
fn drop_index_model(&self, model: IndexModel) -> Result<()>
Drop an index by IndexModel.
fn drop_indexes(&self) -> Result<()>
Drop all indexes in the collection.
fn list_indexes(&self) -> Result<Cursor>
List all indexes in the collection.