Struct polodb_core::Collection
source · pub struct Collection<'a, T> { /* private fields */ }
Expand description
A wrapper of collection in struct.
All CURD methods can be done through this structure.
It can be used to perform collection-level operations such as CRUD operations.
Implementations§
source§impl<'a, T> Collection<'a, T>
impl<'a, T> Collection<'a, T>
pub fn name(&self) -> &str
sourcepub fn count_documents(&self) -> DbResult<u64>
pub fn count_documents(&self) -> DbResult<u64>
Return the size of all data in the collection.
sourcepub fn count_documents_with_session(
&self,
session: &mut ClientSession<'_>
) -> DbResult<u64>
pub fn count_documents_with_session( &self, session: &mut ClientSession<'_> ) -> DbResult<u64>
Return the size of all data in the collection.
sourcepub fn update_one(
&self,
query: Document,
update: Document
) -> DbResult<UpdateResult>
pub fn update_one( &self, query: Document, update: Document ) -> DbResult<UpdateResult>
Updates up to one document matching query
in the collection.
documentation for more information on specifying updates.
sourcepub fn update_one_with_session(
&self,
query: Document,
update: Document,
session: &mut ClientSession<'_>
) -> DbResult<UpdateResult>
pub fn update_one_with_session( &self, query: Document, update: Document, session: &mut ClientSession<'_> ) -> DbResult<UpdateResult>
Updates up to one document matching query
in the collection.
documentation for more information on specifying updates.
sourcepub fn update_many(
&self,
query: Document,
update: Document
) -> DbResult<UpdateResult>
pub fn update_many( &self, query: Document, update: Document ) -> DbResult<UpdateResult>
Updates all documents matching query
in the collection.
documentation for more information on specifying updates.
sourcepub fn update_many_with_session(
&self,
query: Document,
update: Document,
session: &mut ClientSession<'_>
) -> DbResult<UpdateResult>
pub fn update_many_with_session( &self, query: Document, update: Document, session: &mut ClientSession<'_> ) -> DbResult<UpdateResult>
Updates all documents matching query
in the collection.
documentation for more information on specifying updates.
sourcepub fn delete_one(&self, query: Document) -> DbResult<DeleteResult>
pub fn delete_one(&self, query: Document) -> DbResult<DeleteResult>
Deletes up to one document found matching query
.
sourcepub fn delete_one_with_session(
&self,
query: Document,
session: &mut ClientSession<'_>
) -> DbResult<DeleteResult>
pub fn delete_one_with_session( &self, query: Document, session: &mut ClientSession<'_> ) -> DbResult<DeleteResult>
Deletes up to one document found matching query
.
sourcepub fn delete_many(&self, query: Document) -> DbResult<DeleteResult>
pub fn delete_many(&self, query: Document) -> DbResult<DeleteResult>
When query is None
, all the data in the collection will be deleted.
The size of data deleted returns.
sourcepub fn delete_many_with_session(
&self,
query: Document,
session: &mut ClientSession<'_>
) -> DbResult<DeleteResult>
pub fn delete_many_with_session( &self, query: Document, session: &mut ClientSession<'_> ) -> DbResult<DeleteResult>
When query is None
, all the data in the collection will be deleted.
The size of data deleted returns.
pub fn drop(&self) -> DbResult<()>
pub fn drop_with_session(&self, session: &mut ClientSession<'_>) -> DbResult<()>
source§impl<'a, T> Collection<'a, T>where
T: Serialize,
impl<'a, T> Collection<'a, T>where T: Serialize,
sourcepub fn insert_one(&self, doc: impl Borrow<T>) -> DbResult<InsertOneResult>
pub fn insert_one(&self, doc: impl Borrow<T>) -> DbResult<InsertOneResult>
Inserts doc
into the collection.
sourcepub fn insert_one_with_session(
&self,
doc: impl Borrow<T>,
session: &mut ClientSession<'_>
) -> DbResult<InsertOneResult>
pub fn insert_one_with_session( &self, doc: impl Borrow<T>, session: &mut ClientSession<'_> ) -> DbResult<InsertOneResult>
Inserts doc
into the collection.
sourcepub fn insert_many(
&self,
docs: impl IntoIterator<Item = impl Borrow<T>>
) -> DbResult<InsertManyResult>
pub fn insert_many( &self, docs: impl IntoIterator<Item = impl Borrow<T>> ) -> DbResult<InsertManyResult>
Inserts the data in docs
into the collection.
sourcepub fn insert_many_with_session(
&self,
docs: impl IntoIterator<Item = impl Borrow<T>>,
session: &mut ClientSession<'_>
) -> DbResult<InsertManyResult>
pub fn insert_many_with_session( &self, docs: impl IntoIterator<Item = impl Borrow<T>>, session: &mut ClientSession<'_> ) -> DbResult<InsertManyResult>
Inserts the data in docs
into the collection.
source§impl<'a, T> Collection<'a, T>where
T: DeserializeOwned,
impl<'a, T> Collection<'a, T>where T: DeserializeOwned,
sourcepub fn find_many(&self, filter: impl Into<Option<Document>>) -> DbResult<Vec<T>>
pub fn find_many(&self, filter: impl Into<Option<Document>>) -> DbResult<Vec<T>>
When query document is passed to the function. The result satisfies the query document.
sourcepub fn find_many_with_session(
&self,
filter: impl Into<Option<Document>>,
session: &mut ClientSession<'_>
) -> DbResult<Vec<T>>
pub fn find_many_with_session( &self, filter: impl Into<Option<Document>>, session: &mut ClientSession<'_> ) -> DbResult<Vec<T>>
When query document is passed to the function. The result satisfies the query document.
sourcepub fn find_one(
&self,
filter: impl Into<Option<Document>>
) -> DbResult<Option<T>>
pub fn find_one( &self, filter: impl Into<Option<Document>> ) -> DbResult<Option<T>>
Return the first element in the collection satisfies the query.
sourcepub fn find_one_with_session(
&self,
filter: impl Into<Option<Document>>,
session: &mut ClientSession<'_>
) -> DbResult<Option<T>>
pub fn find_one_with_session( &self, filter: impl Into<Option<Document>>, session: &mut ClientSession<'_> ) -> DbResult<Option<T>>
Return the first element in the collection satisfies the query.