mongo-embedded
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:
- OS/Arch Detection: Automatically selects the correct binary for Linux, macOS, and Windows.
- Downloading: Fetches the binary from the official MongoDB download center.
- Extraction: Unpacks
.tgzor.ziparchives. - Execution: Starts the
mongodprocess on a specified port.
Usage
Installation
Run the following command in your project directory:
Or add the following to your Cargo.toml:
[]
= "1.0.0"
= { = "1.0", = ["full"] } # Required for the example below
Example
use MongoEmbedded;
use ;
async
With Download Progress
use ;
async
process.kill.expect;
}
Check if Installed
You can check if the MongoDB binary for the specified version is already downloaded and extracted:
let mongo = new.unwrap;
if mongo.is_installed
Unix Sockets / Custom Bind IP
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 = new.unwrap
.set_bind_ip;
// Or bind to a specific IP
// let mongo = mongo.set_bind_ip("127.0.0.1");
Configuration
The library uses the directories crate to find suitable locations for:
- Cache: Stores downloaded archives (e.g.,
~/.cache/mongo-embeddedon Linux). - Data: Stores the database files (e.g.,
~/.local/share/mongo-embeddedon Linux).
License
MIT