8 releases

✓ Uses Rust 2018 edition

0.3.0-alpha.1 Sep 29, 2019
0.2.2 Sep 4, 2018
0.1.4 May 28, 2018
0.1.1 Mar 27, 2018

#81 in Database interfaces

Download history 8/week @ 2019-07-22 7/week @ 2019-07-29 12/week @ 2019-08-05 13/week @ 2019-08-19 91/week @ 2019-08-26 34/week @ 2019-09-02 8/week @ 2019-09-09 70/week @ 2019-09-16 24/week @ 2019-09-23 24/week @ 2019-09-30 3/week @ 2019-10-07 11/week @ 2019-10-14 22/week @ 2019-10-21

99 downloads per month

MIT license

26K SLoC


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.


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
$ 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"


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);


~214K SLoC