Skip to content

Latest commit

 

History

History
48 lines (36 loc) · 992 Bytes

File metadata and controls

48 lines (36 loc) · 992 Bytes

First Example

Here is an example code of PoloDB:

use polodb_core::{bson::doc, Database};

fn main() {
    let db = Database::open_memory().unwrap();
    let contacts = db.collection("contacts");

    let john = doc! {
        "Name": "John",
        "Age": 20,
    };

    contacts.insert_one(john).unwrap();

    let people = contacts.find(None).unwrap();
    for person in people {
        println!("{:#?}", person.unwrap());
    }
}

It opens a database in memory, inserts a document into the database and queries all inserted documents.

Output:

Document({
    "Name": String(
        "John",
    ),
    "Age": Int32(
        20,
    ),
    "_id": ObjectId(
        "66bc9e1e13dbc06f151d08b1",
    ),
})

We will explain every parts of the example in detail later.

➡️ Next: Databases, Collections And Documents

📘 Back: Table of contents