93 releases

0.4.22 Sep 8, 2023
0.4.19 Aug 20, 2023
0.4.15 Jul 30, 2023
0.3.18 Mar 27, 2023
0.0.11 Nov 19, 2021

#237 in Database interfaces

Download history 128/week @ 2023-06-08 278/week @ 2023-06-15 105/week @ 2023-06-22 250/week @ 2023-06-29 179/week @ 2023-07-06 134/week @ 2023-07-13 77/week @ 2023-07-20 67/week @ 2023-07-27 98/week @ 2023-08-03 105/week @ 2023-08-10 147/week @ 2023-08-17 148/week @ 2023-08-24 46/week @ 2023-08-31 262/week @ 2023-09-07 33/week @ 2023-09-14 43/week @ 2023-09-21

400 downloads per month
Used in 2 crates

MIT license

47KB
1K SLoC

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

MONGO_URI=mongodb://username:password@localhost:27017

## or

MONGO_ADDRESS=localhost:27017
MONGO_USERNAME=username
MONGO_PASSWORD=password


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

~28–67MB
~1M SLoC