#mongo-db #embedded-database #persistence #in-memory #api #separate #file

bin+lib notmongo

In-process, bad database with an API similar to MongoDB

3 releases

0.1.7 Jul 29, 2023
0.1.6 Jul 29, 2023
0.1.5 Jul 29, 2023

#2428 in Database interfaces

48 downloads per month

MIT license

86KB
2K SLoC

Not Mongo

notmongo is a simple embedded database, for when you really want MongoDB, but running a separate database isn't practical.

All data is kept in-memory. Persistence is achieved by explicitly reading/writing data from/to disk.

// Program start: Read the data from a file
let mut db = Database::new_from_json_file("data/database.json", Compression::None)?;

// Get the collection to search in
let collection = db.collection_mut("collection-1");

// Build the query
let find_query = FindQuery::parse_bson(bson::doc!{"foo": "bar"})?;

// Run it
println!("{:?}", collection.find_one(
    &find_query,  // The query to run
    &HashMap::new(),  // Projection
    &HashMap::new()  // Sorting
));

// Store the database back to disk
db.dump_to_json_file(
    "data/database.json", // Path to the output file
    false, // Use relaxed JSON
    true,  // Format the output
    3,   // Keep 3 old versions of the file as backup
    Compression:None
)?;

Notes

notmongo is really meant as a Python library. The logic is implemented in Rust in order to achieve adequate performance, but Rust is not this library's primary target.

With that said, I see no reason why it shouldn't be usable directly from Rust, hence this package.

Dependencies

~10MB
~190K SLoC