Struct mongo_driver::collection::Collection
[−]
[src]
pub struct Collection<'a> { /* fields omitted */ }
Provides access to a collection for most CRUD operations, I.e. insert, update, delete, find, etc.
A collection instance can be created by calling get_collection
or take_database
on a Client
or Database
instance.
Methods
impl<'a> Collection<'a>
[src]
pub fn aggregate(
&'a self,
pipeline: &Document,
options: Option<&AggregateOptions>
) -> Result<Cursor<'a>>
[src]
&'a self,
pipeline: &Document,
options: Option<&AggregateOptions>
) -> Result<Cursor<'a>>
Execute an aggregation query on the collection. The bson 'pipeline' is not validated, simply passed along as appropriate to the server. As such, compatibility and errors should be validated in the appropriate server documentation.
pub fn command(
&'a self,
command: Document,
options: Option<&CommandAndFindOptions>
) -> Result<Cursor<'a>>
[src]
&'a self,
command: Document,
options: Option<&CommandAndFindOptions>
) -> Result<Cursor<'a>>
Execute a command on the collection.
This is performed lazily and therefore requires calling next
on the resulting cursor.
pub fn command_simple(
&'a self,
command: Document,
read_prefs: Option<&ReadPrefs>
) -> Result<Document>
[src]
&'a self,
command: Document,
read_prefs: Option<&ReadPrefs>
) -> Result<Document>
Simplified version of command
that returns the first document immediately.
pub fn count(
&self,
query: &Document,
options: Option<&CountOptions>
) -> Result<i64>
[src]
&self,
query: &Document,
options: Option<&CountOptions>
) -> Result<i64>
Execute a count query on the underlying collection.
The query
bson is not validated, simply passed along to the server. As such, compatibility and errors should be validated in the appropriate server documentation.
For more information, see the query reference at the MongoDB website.
pub fn create_bulk_operation(
&'a self,
options: Option<&BulkOperationOptions>
) -> BulkOperation<'a>
[src]
&'a self,
options: Option<&BulkOperationOptions>
) -> BulkOperation<'a>
Create a bulk operation. After creating call various functions such as update
,
insert
and others. When calling execute
these operations will be executed in
batches.
pub fn drop(&mut self) -> Result<()>
[src]
Request that a collection be dropped, including all indexes associated with the collection.
pub fn find(
&'a self,
query: &Document,
options: Option<&CommandAndFindOptions>
) -> Result<Cursor<'a>>
[src]
&'a self,
query: &Document,
options: Option<&CommandAndFindOptions>
) -> Result<Cursor<'a>>
Execute a query on the underlying collection.
If no options are necessary, query can simply contain a query such as {a:1}
.
If you would like to specify options such as a sort order, the query must be placed inside of {"$query": {}}
as specified by the server documentation. See the example below for how to properly specify additional options to query.
pub fn find_and_modify(
&'a self,
query: &Document,
operation: FindAndModifyOperation<'a>,
options: Option<&FindAndModifyOptions>
) -> Result<Document>
[src]
&'a self,
query: &Document,
operation: FindAndModifyOperation<'a>,
options: Option<&FindAndModifyOptions>
) -> Result<Document>
Update and return an object. This is a thin wrapper around the findAndModify command. Pass in an operation that either updates, upserts or removes.
pub fn get_name(&self) -> Cow<str>
[src]
Get the name of the collection.
pub fn insert(
&'a self,
document: &Document,
options: Option<&InsertOptions>
) -> Result<()>
[src]
&'a self,
document: &Document,
options: Option<&InsertOptions>
) -> Result<()>
Insert document into collection.
If no _id
element is found in document, then an id will be generated locally and added to the document.
pub fn remove(
&self,
selector: &Document,
options: Option<&RemoveOptions>
) -> Result<()>
[src]
&self,
selector: &Document,
options: Option<&RemoveOptions>
) -> Result<()>
Remove documents in the given collection that match selector.
The bson selector
is not validated, simply passed along as appropriate to the server. As such, compatibility and errors should be validated in the appropriate server documentation.
If you want to limit deletes to a single document, add the SingleRemove
flag.
pub fn save(
&self,
document: &Document,
write_concern: Option<&WriteConcern>
) -> Result<()>
[src]
&self,
document: &Document,
write_concern: Option<&WriteConcern>
) -> Result<()>
Save a document into the collection. If the document has an _id
field it will be updated.
Otherwise it will be inserted.
pub fn update(
&self,
selector: &Document,
update: &Document,
options: Option<&UpdateOptions>
) -> Result<()>
[src]
&self,
selector: &Document,
update: &Document,
options: Option<&UpdateOptions>
) -> Result<()>
This function updates documents in collection that match selector.
By default, updates only a single document. Add MultiUpdate
flag to update multiple documents.
ⓘImportant traits for TailingCursor<'a>pub fn tail(
&'a self,
query: Document,
find_options: Option<CommandAndFindOptions>,
tail_options: Option<TailOptions>
) -> TailingCursor<'a>
[src]
&'a self,
query: Document,
find_options: Option<CommandAndFindOptions>,
tail_options: Option<TailOptions>
) -> TailingCursor<'a>
Tails a query
Takes ownership of query and options because they could be modified and reused when the connections is disrupted and we need to restart the query. The query will be placed in a $query key, so the function can add configuration needed for proper tailing.
The query is executed when iterating, so this function doesn't return a result itself.
The necessary flags to configure a tailing query will be added to the configured flags if you choose to supply options.