Crates.io | notmongo |
lib.rs | notmongo |
version | 0.1.7 |
source | src |
created_at | 2023-07-29 06:17:46.004484 |
updated_at | 2023-07-29 12:02:57.172955 |
description | In-process, bad database with an API similar to MongoDB |
homepage | |
repository | |
max_upload_size | |
id | 929124 |
size | 101,485 |
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
)?;
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.