[][src]Struct polodb_core::db::Collection

pub struct Collection<'a> { /* fields omitted */ }

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:

NameDescription
$eqMatches values that are equal to a specified value.
$gtMatches values that are greater than a specified value.
$gteMatches values that are greater than or equal to a specified value.
$inMatches any of the values specified in an array.
$ltMatches values that are less than a specified value.
$lteMatches values that are less than or equal to a specified value.
$neMatches all values that are not equal to a specified value.
$ninMatches none of the values specified in an array.

Logical operation:

NameDescription
$andJoins query clauses with a logical AND returns all documents that match the conditions of both clauses.
$orJoins 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]

When query is None, all the data in the collection will be updated. Basically the same as MongoDB.

Field Update Operators:

NameDescription
$incIncrements the value of the field by the specified amount.
$minOnly updates the field if the specified value is less than the existing field value.
$maxOnly updates the field if the specified value is greater than the existing field value.
$mulMultiplies the value of the field by the specified amount.
$renameRenames a field.
$setSets the value of a field in a document.
$unsetRemoves 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]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.