8 releases
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 |
#2354 in Database interfaces
22 downloads per month
3.5MB
26K
SLoC
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);
}
}
Dependencies
~4–5.5MB
~94K SLoC