mongodb

package mongodb
MongoDB Nit Driver.

mongodb::native_mongodb

Native wrapper for the MongoDB C Driver

See mongoc.

mongodb::mongodb

module mongodb

MongoDB Nit Driver.

This is actually a wrapper around the MongoDB C Driver.

Usage:

var client = new MongoClient("mongodb://localhost:27017/")

# Select the database.
var db_suffix = "NIT_TESTING_ID".environ
var db_name = "test_{db_suffix}"
var db = client.database(db_name)

# Retrieve a collection.
var col = db.collection("test")

# Insert a document in the collection.
var doc = new JsonObject
doc["foo"] = 10
doc["bar"] = "bar"
doc["baz"] = new JsonArray
assert col.insert(doc)

# Retrieve a document from the collection.
var query = new JsonObject
query["foo"] = 10
var res = col.find(query)
assert res["bar"] == "bar"

mongodb::queries

module queries

Mongo queries framework

The queries framework is used to build Mongo queries as JsonObject with a fluent interface.

Using the queries framework we can get from this:

var exists = new JsonObject
exists["$exists"] = true

var query = new JsonObject
query["login"] = "Morriar"
query["email"] = exists

collection.find(query)

To this:

collection.find((new MongoMatch).eq("login", "Morriar").exists("email", true))

The framework provides three classes used to map the MongoDB query API:

  • MongoMatch the base query that can be used with most Mongo services
  • MongoPipeline the array of queries that is expected by MongoCollection::aggregate
  • MongoGroup the group query for a MongoPipeline

More on this features can be found in the official MongoDB documentation: https://docs.mongodb.com/manual/reference/operator/