47 releases

new 0.0.51 Apr 9, 2025
0.0.50 Mar 24, 2025
0.0.49 Feb 26, 2025
0.0.39 Nov 25, 2024
0.0.13 Mar 28, 2024

#2219 in Database interfaces

Download history 129/week @ 2024-12-28 368/week @ 2025-01-04 95/week @ 2025-01-11 26/week @ 2025-01-18 185/week @ 2025-01-25 231/week @ 2025-02-01 197/week @ 2025-02-08 208/week @ 2025-02-15 241/week @ 2025-02-22 81/week @ 2025-03-01 34/week @ 2025-03-08 68/week @ 2025-03-15 180/week @ 2025-03-22 47/week @ 2025-03-29 220/week @ 2025-04-05

524 downloads per month
Used in 3 crates

MIT license

20KB
394 lines

Quick Microservices MongoDB - qm-mongodb

utilities to work with the MongoDB database


GitHub repositoryCargo packageDocs

github.com - quick-microservice-rs crates.io - qm-mongodb
github.com - workflow - build


Description

With this crate it is easy to get a MongoDB configuration with the most common settings. It also provides common helpers for collections and indexes and provide a convenient way to share clients for database access.

Usage

let mongodb = qm::mongodb::DB::new("example", &qm::mongodb::DbConfig::new()?).await?;

The Config is populated with environment variables. By default, all variables with the prefix MONGODB_ are considered.

The prefix can be changed by using a builder pattern.

let example_config = qm::mongodb::DbConfig::builder().with_prefix("EXAMPLE_").build()?;

Variables and Defaults

These variables are available and are set with the following defaults.

variable struct field default
MONGODB_HOST host "127.0.0.1"
MONGODB_PORT port 27017
MONGODB_USERNAME username
MONGODB_PASSWORD password
MONGODB_DATABASE database "test"
MONGODB_ROOT_USERNAME root_username
MONGODB_ROOT_PASSWORD root_password
MONGODB_ROOT_DATABASE root_database "admin"
MONGODB_SHARDED sharded false
address With credentials: mongodb://{username}:{password}@{host}:{port}/{database};
Without: mongodb://{host}:{port}/{database}
root_address With credentials: mongodb://{root_username}:{root_password}@{host}:{port}/{root_database};
Without: mongodb://{host}:{port}/{root_database}

Dependencies

~17–28MB
~425K SLoC