[−][src]Struct polodb_core::db::Collection
A wrapper of collection in struct.
All CURD methods can be done through this structure.
Find/Update/Delete operations need a query object.
Query operation:
Name | Description |
---|---|
$eq | Matches values that are equal to a specified value. |
$gt | Matches values that are greater than a specified value. |
$gte | Matches values that are greater than or equal to a specified value. |
$in | Matches any of the values specified in an array. |
$lt | Matches values that are less than a specified value. |
$lte | Matches values that are less than or equal to a specified value. |
$ne | Matches all values that are not equal to a specified value. |
$nin | Matches none of the values specified in an array. |
Logical operation:
Name | Description |
---|---|
$and | Joins query clauses with a logical AND returns all documents that match the conditions of both clauses. |
$or | Joins query clauses with a logical OR returns all documents that match the conditions of either clause. |
Example:
use std::rc::Rc; use polodb_core::Database; use polodb_bson::mk_document; let mut db = Database::open("/tmp/test-collection").unwrap(); let mut collection = db.collection("test").unwrap(); collection.insert(mk_document! { "_id": 0, "name": "Vincent Chan", "score": 99.99, }.as_mut());
Implementations
impl<'a> Collection<'a>
[src]
pub fn find(&mut self, query: Option<&Document>) -> DbResult<Vec<Rc<Document>>>
[src]
When query is None
, all the data in the collection return.
When query document is passed to the function. The result satisfies the query document.
pub fn name(&self) -> &str
[src]
pub fn count(&mut self) -> DbResult<u64>
[src]
Return the size of all data in the collection.
pub fn update(
&mut self,
query: Option<&Document>,
update: &Document
) -> DbResult<usize>
[src]
&mut self,
query: Option<&Document>,
update: &Document
) -> DbResult<usize>
When query is None
, all the data in the collection will be updated.
Basically the same as MongoDB.
Field Update Operators:
Name | Description |
---|---|
$inc | Increments the value of the field by the specified amount. |
$min | Only updates the field if the specified value is less than the existing field value. |
$max | Only updates the field if the specified value is greater than the existing field value. |
$mul | Multiplies the value of the field by the specified amount. |
$rename | Renames a field. |
$set | Sets the value of a field in a document. |
$unset | Removes the specified field from a document. |
pub fn insert(&mut self, doc: &mut Document) -> DbResult<bool>
[src]
pub fn delete(&mut self, query: Option<&Document>) -> DbResult<usize>
[src]
When query is None
, all the data in the collection will be deleted.
The size of data deleted returns.
Auto Trait Implementations
impl<'a> !RefUnwindSafe for Collection<'a>
impl<'a> !Send for Collection<'a>
impl<'a> !Sync for Collection<'a>
impl<'a> Unpin for Collection<'a>
impl<'a> !UnwindSafe for Collection<'a>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
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.
pub 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>,