[−][src]Struct avocado::coll::Collection
A statically-typed (homogeneous) MongoDB
collection.
Methods
impl<T: Doc> Collection<T>
[src]
pub fn create_indexes(&self) -> Result<()>
[src]
Creates indexes on the underlying MongoDB
collection
according to the given index specifications.
pub fn drop(&self) -> Result<()>
[src]
Deletes the collection.
pub fn count<Q: Count<T>>(&self, query: Q) -> Result<usize>
[src]
Returns the number of documents matching the query criteria.
pub fn distinct<Q, C>(&self, query: Q) -> Result<C> where
Q: Distinct<T>,
C: FromIterator<Q::Output>,
[src]
Q: Distinct<T>,
C: FromIterator<Q::Output>,
Returns the distinct values of a certain field.
pub fn aggregate<P: Pipeline<T>>(
&self,
pipeline: P
) -> Result<Cursor<P::Output>>
[src]
&self,
pipeline: P
) -> Result<Cursor<P::Output>>
Runs an aggregation pipeline.
pub fn find_one<Q: Query<T>>(&self, query: Q) -> Result<Option<Q::Output>>
[src]
Retrieves a single document satisfying the query, if one exists.
pub fn find_many<Q: Query<T>>(&self, query: Q) -> Result<Cursor<Q::Output>>
[src]
Retrieves all documents satisfying the query.
pub fn insert_one(&self, entity: &T) -> Result<Uid<T>>
[src]
Inserts a single document.
pub fn insert_many<I>(&self, entities: I) -> Result<BTreeMap<u64, Uid<T>>> where
I: IntoIterator,
I::Item: Borrow<T>,
I::IntoIter: ExactSizeIterator,
T::Id: Clone + Debug,
T: 'static,
[src]
I: IntoIterator,
I::Item: Borrow<T>,
I::IntoIter: ExactSizeIterator,
T::Id: Clone + Debug,
T: 'static,
Inserts many documents.
If this method fails to insert all documents, the returned error will
contain as context info the IDs of the documents successfully inserted.
If possible, each ID will be deserialized as an Ok(Uid<T>)
; otherwise
the context map will contain an Err(Bson)
with the original raw value
for IDs which couldn't be deserialized.
The context map can be accessed as: error.context::<InsertManyErrorContext<T>>()
pub fn replace_entity(&self, entity: &T) -> Result<UpdateOneResult> where
T: Debug,
[src]
T: Debug,
Convenience method for updating a single document based on identity (its
_id
field), setting all fields to the values supplied by entity
.
This doesn't add a new document if none with the specified _id
exists.
pub fn upsert_entity(&self, entity: &T) -> Result<UpsertOneResult<Uid<T>>> where
T: Debug,
[src]
T: Debug,
Convenience method for updating a single document based on identity (its
_id
field), setting all fields to the values supplied by entity
.
This method adds a new document if none with the specified _id
exists.
pub fn update_one<U: Update<T>>(&self, update: U) -> Result<UpdateOneResult>
[src]
Updates a single document.
This method only works with update operators (with field names starting
with $
), i.e. it does not replace entire documents.
pub fn upsert_one<U: Upsert<T>>(
&self,
upsert: U
) -> Result<UpsertOneResult<Uid<T>>>
[src]
&self,
upsert: U
) -> Result<UpsertOneResult<Uid<T>>>
Upserts a single document.
This method only works with update operators (with field names starting
with $
), i.e. it does not replace entire documents.
pub fn update_many<U: Update<T>>(&self, update: U) -> Result<UpdateManyResult>
[src]
Updates multiple documents.
This method only works with update operators (with field names starting
with $
), i.e. it does not replace entire documents.
pub fn upsert_many<U: Upsert<T>>(&self, upsert: U) -> Result<UpsertManyResult>
[src]
Upserts multiple documents (updates many or inserts one if none found).
This method only works with update operators (with field names starting
with $
), i.e. it does not replace entire documents.
pub fn delete_entity(&self, entity: &T) -> Result<bool> where
T: Debug,
[src]
T: Debug,
Convenience method for deleting a single entity based on its identity
(the _id
field). Returns true
if it was found and deleted.
pub fn delete_entities<I>(&self, entities: I) -> Result<usize> where
I: IntoIterator,
I::Item: Borrow<T>,
T: Debug,
[src]
I: IntoIterator,
I::Item: Borrow<T>,
T: Debug,
Convenience method for deleting entities based on their identity
(the _id
fields). Returns the number of deleted documents.
pub fn delete_one<Q: Delete<T>>(&self, query: Q) -> Result<bool>
[src]
Deletes one document. Returns true
if one was found and deleted.
pub fn delete_many<Q: Delete<T>>(&self, query: Q) -> Result<usize>
[src]
Deletes many documents. Returns the number of deleted documents.
pub fn find_one_and_delete<Q: Query<T>>(
&self,
query: Q
) -> Result<Option<Q::Output>>
[src]
&self,
query: Q
) -> Result<Option<Q::Output>>
Deletes a single document based on the query criteria, returning it if it was found.
pub fn find_one_and_replace<Q: Query<T>>(
&self,
query: Q,
replacement: &T
) -> Result<Option<Q::Output>> where
T: Debug,
[src]
&self,
query: Q,
replacement: &T
) -> Result<Option<Q::Output>> where
T: Debug,
Replaces a single document based on the query criteria. Returns the original document if found.
This method does not provide an option for returning the updated document, since it already requires the presence of a replacement.
pub fn find_one_and_update<U: FindAndUpdate<T>>(
&self,
update: U
) -> Result<Option<U::Output>>
[src]
&self,
update: U
) -> Result<Option<U::Output>>
Finds a single document based on query criteria and updates it.
For convenience reasons, unlike others, this API is NOT split into
separate update and upsert functions. The options returned by the
update
argument decide whether an update or an upsert happens.
Trait Implementations
Auto Trait Implementations
impl<T> Send for Collection<T> where
T: Send,
T: Send,
impl<T> Unpin for Collection<T> where
T: Unpin,
T: Unpin,
impl<T> Sync for Collection<T> where
T: Sync,
T: Sync,
impl<T> UnwindSafe for Collection<T> where
T: UnwindSafe,
T: UnwindSafe,
impl<T> RefUnwindSafe for Collection<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
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> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
U: TryFrom<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> DebugAny for T where
T: Any + Debug,
[src]
T: Any + Debug,
impl<T> UnsafeAny for T where
T: Any,
T: Any,