Simple object persistence with MongoDB


Simple object persistence for node.js with MongoDB.

var lian = require('lian')('localhost/mydb');

function Person (name) {
    lian(this, 'person'); = name;

Person.prototype.getGender = function () {
    return this.gender;

var john = new Person('John Smith');
john.gender = "male";;

Create a projection of Person to find the instance saved above.

var john = new Person('John Smith');
john.find().then(function (results) {

    john = results[0];; // "John Smith"
    john.getGender(); // "male"

Make some changes to persist. = "John Anthony Smith";;

Decoupled, lian's Store object can be used directly.

var Store = require('lian').Store,
    lian  = require('lian');

function Person (name) {
    lian(this, 'person'); = name;

var steve = new Person('steve');

typeof steve.insert // "undefined"

var store = new Store('localhost/mydb');
  • Avoid writing result to object mapping code over and over.
  • Instance based connections, multiple connections within the same process.
  • All asynchronous operations should return a promise.
  • Store provides an in-memory alternative, for testing.


Lian uses monk to talk to MongoDB and promised-io for futures.

Clone the repo...

git clone git://

Use npm to install dependencies.

cd lian && \
npm install --dev

Run the tests.

make test

The tests mock out monk, there are integration tests expecting a MongoDB instance running on localhost:27017. They will create a lian-integration database.

make integration-test