Struct polodb_core::db::Collection [−][src]
pub struct Collection<'a> { /* fields omitted */ }
Expand description
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::doc;
let mut db = Database::open_file("/tmp/test-collection").unwrap();
let mut collection = db.collection("test").unwrap();
collection.insert(doc! {
"_id": 0,
"name": "Vincent Chan",
"score": 99.99,
}.as_mut());
Implementations
all the data in the collection return.
When query document is passed to the function. The result satisfies the query document.
Return the first element in the collection satisfies the query.
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. |
Insert a document into the database. The returning boolean value represents if the DB inserted a “_id” for you.