This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let cursor = match coll.find(doc! { age: { $gte: 18 } } , None) { | |
Ok(cursor) => cursor, | |
Err(error) => println!("The following error occured: {}", error) | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Generate a list of InsertOne write models. | |
let models = (1..5).map(|i| WriteModel::InsertOne { document: doc! { | |
"_id" => (i), | |
"x" => (i * 11) | |
}}).collect(); | |
let new_coll = db.collection("example"); | |
// Execute InsertOne operations, ordered. | |
new_coll.bulk_write(models, true); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let coll = db.collection("comedies"); | |
let film_a = doc!{ "title" => "Ferris Bueller’s Day Off" }; | |
let film_b = doc!{ "title" => "Airplane!" }; | |
// Insert multiple documents with default options. | |
coll.insert_many(vec![film_a, film_b], None) | |
.ok().expect("Failed to insert documents."); | |
// Update a single document. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.auth("root", "very_secure_password") | |
.ok().expect("Failed to authorize user 'root'."); | |
// List collections without a filter. | |
let collections = db.list_collections(None) | |
.ok().expect(“Are you sure you’ve been authorized?”); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let db = client.db("movies"); | |
let options = CreateCollectionOptions::new(); | |
options.capped = true; | |
options.size = Some(100000); | |
db.create_collection("comedies", Some(options)) | |
.ok().expect("Failed to create 'comedies' collection!"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let client = Client::with_uri("mongodb://localhost:27017,localhost:27018") | |
.ok().expect("Failed to initialize client."); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let client = Client::connect("localhost", 27017) | |
.ok().expect("Failed to initialize client."); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[macro_use(bson, doc)] | |
extern crate bson; | |
extern crate mongodb; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[dependencies] | |
bson = "0.1.3" | |
mongodb = "0.1.0" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local MongoClient = require("luaMongo.MongoClient") | |
local client = MongoClient.new("mongodb://localhost:27017/") | |
local exampleDatabase = client:getDatabase("exampleDB") | |
local exampleCollection = exampleDatabase:getCollection("exampleCollection") | |
-- Create document to insert. | |
local document_to_insert = {foo = "bar"} | |
-- Insert document into database | |
exampleCollection:insert_one(document_to_insert) |