Quick start
Open a database
Filesystem backend
With the filesystem backend, PoloDB stores data in ONE file. All the data are saved persistently on the disk.
use polodb_core::Database;
let db = Database::open_file("test-polo.db").unwrap();
Do NOT open a database on a network volume.
Memory backend
With the memory backend, all the data all stored in memory, making PoloDB a pure memory database.
use polodb_core::Database;
let db = Database::open_memory().unwrap();
Collection
A Collection is a dataset of a kind of data.
You can use create_collection
to create a data collection.
To obtain an exist collection, use the method collection
.
let test_collection = db.collection("test");
Document
A document is a row of JSON data in PoloDB. PoloDB uses an extended JSON which supports extended types such as Data and ObjectID.
PoloDB uses the property _id
as the primary key of the row of the data.
If the document doesn't have an id, PoloDB will generate one automatically.
Internally, PoloDB uses bson (opens in a new tab) to encode the data, which is small an fast.
An document can be constructed by the macro:
use polodb_core::bson::doc;
let keys = doc! {
"user_id": 1,
};