Skip to content
[project inactive] Mongolian DeadBeef is an awesome Mongo DB driver for node.js
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Mongolian DeadBeef

Mongolian DeadBeef is an awesome Mongo DB node.js driver that sits on top of node-mongodb-native and attempts to closely approximate the mongodb shell.


Mongolian DeadBeef and its documentation is super under construction! Go check out examples/mongolian_trainer.js and the rest of the source!


WARNING! The API is super experimental, and will be adding, removing, and changing the API regularly. Use at your own risk

You can either clone the source and install with npm link, or install the latest published version from npm with npm install mongolian.

Running Tests

Run the tests with npm test.


Not a fan of existing asynchronous mongodb apis for node.js, I set out to write my own. To avoid completely reinventing the wheel, much of the Mongolian DeadBeef API is inspired by the mongodb shell.

High level principles:

  • Less is more
    • Nothing is added without careful consideration
    • Remove everything but the essentials
    • Each refactor should remove as much unnecessary lines of code as possible
  • Fail early and often
    • If I can easily detect a programmer error, an exception will be thrown


  • mongodb is pretty simple, much of its functionality is defined as queries on special databases
    • This allows for lots of code reuse
  • Avoid callbacks unless they are absolutely necessary


Most of the work in MongolianDeadBeef doesn't occur until a query is actually made. This means that simple operations are fast and synchronous. Currently there is one connection per server. You can have multiple queries simultaneously on a single mongodb connection, so I'm not sure how important pooling is at this point.


var Mongolian = require("mongolian")

// Create a server instance with default host and port
var server = new Mongolian

// Get database
var db = server.db("awesome_blog")

// Get some collections
var posts = db.collection("posts")
var comments = db.collection("comments")

// Insert some data
    pageId: "hallo"
    title: "Hallo",
    created: new Date,
    body: "Welcome to my new blog!"

// Get a single document
posts.findOne({ pageId: "hallo" }, function(err, post) {

// Document cursors
posts.find().limit(5).sort({ created: 1 }).toArray(function (err, array) {
    // do something with the array
posts.find({ title: /^hal/ }).forEach(function (post) {
    // do something with a single post
}, function(err) {
    // handle errors/completion

Extended Examples

// Create a server with a specific host/port
var server = new Mongolian({

// Create a server with a 15 second connection keep-alive
var server = new Mongolian({ keepAlive:15000 })

// Authenticate a database
db.auth(username, password)

// GridFS
var gridfs = db.gridfs()

// Writing to GridFS consists of creating a GridFS file:
var file = gridfs.create({
// And getting writable Stream (see )
var stream = file.writeStream()

// You can then pipe a local file to that stream easily with:

// Reading a file from GridFS is similar:
gridfs.findOne("License", function (err, file) {
    if (!err && file) {
        // Get the read stream:
        var stream = file.readStream()

        // You could then pipe the file out to a http response, for example:


  • Various utility methods
  • More unit tests
  • Documentation
  • Connection pooling
  • Cleanup


Try it out and send me feedback! That's the best help I could use right now. Unit tests are good, too.


Mongolian DeadBeef is open source software under the zlib license.

Something went wrong with that request. Please try again.