| Crates.io | mongo-embedded |
| lib.rs | mongo-embedded |
| version | 1.0.0 |
| created_at | 2025-12-22 01:30:58.730565+00 |
| updated_at | 2026-01-12 01:42:41.873518+00 |
| description | A library to download, extract, and convert MongoDB Community Edition into an embedded server. |
| homepage | |
| repository | https://github.com/adhil/mongo-embedded |
| max_upload_size | |
| id | 1998885 |
| size | 110,518 |
A Rust library that simplifies using MongoDB for local testing and development by automatically downloading, extracting, and running a MongoDB Community Edition binary.
It handles:
.tgz or .zip archives.mongod process on a specified port.Run the following command in your project directory:
cargo add mongo-embedded
Or add the following to your Cargo.toml:
[dependencies]
mongo-embedded = "1.0.0"
tokio = { version = "1.0", features = ["full"] } # Required for the example below
use mongo_embedded::MongoEmbedded;
use tokio::time::{sleep, Duration};
#[tokio::main]
async fn main() {
let mongo = MongoEmbedded::new("7.0.2").unwrap()
.set_port(12345);
let mut process = mongo.start().await.expect("Failed to start MongoDB");
// MongoDB is running at mongodb://127.0.0.1:12345/
sleep(Duration::from_secs(5)).await;
process.kill().expect("Failed to kill MongoDB process");
}
use mongo_embedded::{MongoEmbedded, DownloadProgress};
#[tokio::main]
async fn main() {
let mongo = MongoEmbedded::new("7.0.2").unwrap();
let mut process = mongo.start_with_progress(|progress: DownloadProgress| {
if let Some(pct) = progress.percentage {
println!("Downloading: {:.1}%", pct);
} else {
println!("Downloaded: {} bytes", progress.downloaded);
}
}).await.expect("Failed to start MongoDB");
process.kill().expect("Failed to kill MongoDB process");
}
process.kill().expect("Failed to kill MongoDB process");
}
You can check if the MongoDB binary for the specified version is already downloaded and extracted:
let mongo = MongoEmbedded::new("7.0.2").unwrap();
if mongo.is_installed() {
println!("MongoDB is ready to start");
}
You can configure the bind IP address. This is useful for security (binding only to localhost) or for using Unix domain sockets (on Unix-like systems) to avoid opening a TCP port.
// Use a Unix socket
let mongo = MongoEmbedded::new("7.0.2").unwrap()
.set_bind_ip("/tmp/mongodb-27017.sock");
// Or bind to a specific IP
// let mongo = mongo.set_bind_ip("127.0.0.1");
The library uses the directories crate to find suitable locations for:
~/.cache/mongo-embedded on Linux).~/.local/share/mongo-embedded on Linux).MIT