[−][src]Struct mongodb::coll::Collection
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]
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.
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]
&self,
pipeline: Vec<Document>,
options: Option<AggregateOptions>
) -> Result<Cursor>
Runs an aggregation framework pipeline.
pub fn count(
&self,
filter: Option<Document>,
options: Option<CountOptions>
) -> Result<i64>
[src]
&self,
filter: Option<Document>,
options: Option<CountOptions>
) -> Result<i64>
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]
&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.
pub fn find(
&self,
filter: Option<Document>,
options: Option<FindOptions>
) -> Result<Cursor>
[src]
&self,
filter: Option<Document>,
options: Option<FindOptions>
) -> Result<Cursor>
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]
&self,
filter: Option<Document>,
options: Option<FindOptions>
) -> Result<Option<Document>>
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]
&self,
filter: Option<Document>,
options: Option<FindOptions>,
cmd_type: CommandType
) -> Result<Option<Document>>
pub fn find_one_and_delete(
&self,
filter: Document,
options: Option<FindOneAndDeleteOptions>
) -> Result<Option<Document>>
[src]
&self,
filter: Document,
options: Option<FindOneAndDeleteOptions>
) -> Result<Option<Document>>
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]
&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.
pub fn find_one_and_update(
&self,
filter: Document,
update: Document,
options: Option<FindOneAndUpdateOptions>
) -> Result<Option<Document>>
[src]
&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.
pub fn bulk_write(
&self,
requests: Vec<WriteModel>,
ordered: bool
) -> BulkWriteResult
[src]
&self,
requests: Vec<WriteModel>,
ordered: bool
) -> BulkWriteResult
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]
&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.
pub fn insert_many(
&self,
docs: Vec<Document>,
options: Option<InsertManyOptions>
) -> Result<InsertManyResult>
[src]
&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.
pub fn delete_one(
&self,
filter: Document,
write_concern: Option<WriteConcern>
) -> Result<DeleteResult>
[src]
&self,
filter: Document,
write_concern: Option<WriteConcern>
) -> Result<DeleteResult>
Deletes a single document.
pub fn delete_many(
&self,
filter: Document,
write_concern: Option<WriteConcern>
) -> Result<DeleteResult>
[src]
&self,
filter: Document,
write_concern: Option<WriteConcern>
) -> Result<DeleteResult>
Deletes multiple documents.
pub fn replace_one(
&self,
filter: Document,
replacement: Document,
options: Option<ReplaceOptions>
) -> Result<UpdateResult>
[src]
&self,
filter: Document,
replacement: Document,
options: Option<ReplaceOptions>
) -> Result<UpdateResult>
Replaces a single document.
pub fn update_one(
&self,
filter: Document,
update: Document,
options: Option<UpdateOptions>
) -> Result<UpdateResult>
[src]
&self,
filter: Document,
update: Document,
options: Option<UpdateOptions>
) -> Result<UpdateResult>
Updates a single document.
pub fn update_many(
&self,
filter: Document,
update: Document,
options: Option<UpdateOptions>
) -> Result<UpdateResult>
[src]
&self,
filter: Document,
update: Document,
options: Option<UpdateOptions>
) -> Result<UpdateResult>
Updates multiple documents.
pub fn create_index(
&self,
keys: Document,
options: Option<IndexOptions>
) -> Result<String>
[src]
&self,
keys: Document,
options: Option<IndexOptions>
) -> Result<String>
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]
&self,
keys: Document,
options: Option<IndexOptions>
) -> Result<()>
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]
&self
) -> Result<impl Iterator<Item = Result<IndexModel>>>
List all indexes in the collection as serialized IndexModel
s.
This is the same as list_indexes
, and still uses a Cursor
under the hood. The elements
are serialized as IndexModel
s as they are received.
Trait Implementations
Auto Trait Implementations
impl Sync for Collection
impl Unpin for Collection
impl Send for Collection
impl UnwindSafe for Collection
impl RefUnwindSafe for Collection
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,
fn vzip(self) -> V
impl<T> Same<T> for T
type Output = T
Should always be Self