103 releases (3 stable)

1.1.0 Aug 30, 2024
1.0.0 Jun 27, 2024
0.5.6 May 18, 2024
0.5.4 Jan 6, 2024
0.0.11 Nov 19, 2021

#1272 in Database interfaces

Download history 13/week @ 2024-07-22 19/week @ 2024-07-29 46/week @ 2024-08-05 198/week @ 2024-08-12 26/week @ 2024-08-19 163/week @ 2024-08-26 15/week @ 2024-09-02 7/week @ 2024-09-09 59/week @ 2024-09-16 27/week @ 2024-09-23 60/week @ 2024-09-30 72/week @ 2024-10-07 41/week @ 2024-10-14 26/week @ 2024-10-21 23/week @ 2024-10-28 19/week @ 2024-11-04

119 downloads per month
Used in 2 crates

MIT license

18KB
582 lines

mungos

inspired by the mongoose npm package, this crate contains the Mungos struct, a wrapper around the mongodb client containing some additional queries and functionality

usage

#[derive(Serialize, Deserialize, Debug)]
struct TestDoc {
	timestamp: i64,
	name: String,
	#[serde(default)]
	description: String,
}

let mungos = mungos::Mungos::new(uri, app_name, Duration::from_secs(3), None).await.unwrap();
let coll = mungos.collection::<TestDoc>("test_db", "test_coll");

let items: Vec<TestDoc> = coll
	.get_most_recent(
		"timestamp", 
		10, 
		0, 
		None, 
		mungos::Projection("timestamp name")
	)
	.await
	.unwrap();

println!("{items:#?}"); // prints the 10 most recent docs by timestamp

initializing from environment

# specify full uri directly
MONGO_URI=mongodb://username:password@localhost:27017

## or

# specify uri parts
MONGO_ADDRESS=localhost:27017
MONGO_USERNAME=username
MONGO_PASSWORD=password

# ---------------------

# specify other options
MONGO_APP_NAME=tester # optional. default is 'mungos'
MONGO_TIMEOUT_SECS=30 # optional. default is '3'
MONGO_COMPRESSORS=snappy,zstd(10),zlib(8) # optional. defaults to None
let mungos = mungos::Mungos::new_from_env().await.unwrap();
let coll = mungos.collection::<TestDoc>("test_db", "test_coll");

let items = coll.get_some(None, None).await.unwrap(); // Vec<TestDoc>

Dependencies

~15–25MB
~378K SLoC