mongors

Crates.iomongors
lib.rsmongors
version0.3.0-alpha.1
sourcesrc
created_at2018-03-13 03:47:47.632987
updated_at2019-09-29 07:09:16.608597
descriptionRust driver for MongoDB
homepagehttps://github.com/danc/mongo-rust-driver
repositoryhttps://github.com/danc/mongo-rust-driver
max_upload_size
id55265
size7,475,333
(danclive)

documentation

https://docs.rs/mongors

README

mongo-rust-driver

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.

$ 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);
    }
}
Commit count: 0

cargo fmt