Git Product home page Git Product logo

mungos's Introduction

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>

mungos's People

Contributors

mbecker20 avatar beckerinj avatar karamvirsingh98 avatar moghtech avatar

Stargazers

 avatar  avatar  avatar 解海 avatar Fatih Al-Aziz avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.