docs
Quick start

Quick start

Open a database

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_path("test-polo.db").unwrap();
⚠️

Do NOT open a database on a network volume.

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");
test_collection.insert_one(
    doc! { "title": "1984", "author": "George Orwell" },
)?;

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,
};