[][src]Crate mongors

Rust driver for MongoDB build on top of libmongoc.

Before that, I originally intended to write this driver completely with rust. Due to limited time and effort, I had to give up this decision. Fortunately, libmongoc is good enough and has official support. So from v0.3, this driver Built on top of libmongoc. This driver provides two sets of apis by wrapping libmongoc. One set is closer to libmongoc. It is almost directly translated libmongoc api into rust, called core. The other set is based on core. The upper level, rust-style api. In general, you can use this set of apis, I have blocked a lot of details for you, client, db and collection are already thread-safe, there is also a useful Bson library. If you don't like this set of apis, you can use core directly, but you have to read the libmongoc documentation, you have to pay attention to a lot of details.

Installation:

To use this library, you first need to compile and install libmongoc.

This example is not tested
$ wget https://github.com/mongodb/mongo-c-driver/releases/download/1.14.0/mongo-c-driver-1.14.0.tar.gz
$ tar xzf mongo-c-driver-1.14.0.tar.gz
$ cd mongo-c-driver-1.14.0
$ mkdir cmake-build
$ cd cmake-build
$ cmake -DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF ..
$ make
$ sudo make install

You can see: http://mongoc.org/libmongoc/current/installing.html

Unfortunately, only Linux systems are currently only partially supported. Since I don't have a computer with other systems, I haven't tried it. If you can, you can modify build.rs to compile on your system. Welcome to submit PR.

Then, you need to add it to the Cargo.toml file:

mongors = "0.3"

Example:

use mongors::*;
use bsonrs::doc;
 
fn main() {
    let client = Mongo::new("mongodb://localhost:27017/?maxpoolsize=10").unwrap();
 
    let db = client.db("test");
 
    let collection = db.collection("test");
 
 
    let mut cursor = collection.find(doc!{}, None, None).unwrap();
 
    for doc in &mut cursor {
        println!("{:?}", doc);
    }
}

Re-exports

pub use uri::Uri;
pub use client::Mongo;
pub use client::Client;
pub use client::MongoBuilder;
pub use db::DB;
pub use collection::Collection;
pub use cursor::Cursor;
pub use read_preference::ReadMode;
pub use read_preference::ReadPreference;
pub use read_concern::ReadConcern;
pub use read_concern::ReadConcernLevel;
pub use write_concern::WriteConcern;
pub use crate::core::mongo_init;
pub use crate::core::mongo_cleanup;

Modules

aggregate
apm
bson
change_stream
client
collection
command
core
cursor
db
error
read_concern
read_preference
session
sys
transaction
uri
write_concern