Skip to content


Subversion checkout URL

You can clone with
Download ZIP
A JS ORM for both server and browser providing Rest server connect middleware
tag: v0.1.0

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.


A JS ORM for nodejs and mongo-db


rest-mongo is a wrapper around node-mongodb-native for easier use of MongoDB from nodejs. It provides high level functions to interact with your objects, which are generated from a JSON schema.


A Schema describing a person

var schema = {
  "Person": {
    schema: {
      id: "Person",
      description: "someone, blablabla",
      type: "object",
      properties: {
        firstname: {type: "string"},
        friends: {type: "array", items: {"$ref": "Person"}},
        mother: {"$ref": "Person"}

The schema describes a document. It can have references or list of references to other documents.

Get a unit of work (we call it 'R'):

var rest_mongo = require("rest-mongo");
var RFactory = rest_mongo.getRFactory(schema, "db_name");
var R = RFactory();

Get a new R every time you need to get a new context to work in (at every client request for example).

Create and save an object into the DB

var lilly = new R.Person({firstname: "Lilly"}); {
  sys.puts("Lilly saved in DB with id " +;

Get one or more objects from DB

}, function(lilly2){
  // lilly and lilly2 are the same

Search in DB

 query: {firstname: "Lilly"}
}, function(data){
  var lilly = data[0];

Delete an object

  sys.puts('Lilly deleted from DB!');
}, function() {
  sys.puts('You can not delete Lily!');

Usage of references:

var harry = new R.Person({firstname: "Harry", mother: lilly}); {
  sys.puts('Only the id of Lilly has been saved in harry.mother in DB.');

Update more than one field in once:

  ids: [,], 
  data: {firstname: 'anonymous'}
}, function() {
  sys.puts("Voldemort cannot find them anymore...");

Save more than on field in once:

var p1 = new R.Person({firstname: 'Hermione'});
var p2 = new R.Person({firstname: 'Ron'});[p1, p2], function() {
  console.log('Now Harry has friends.')
}, function(error) {
  console.log('Harry has no friends, because of ', error);


This version has been tested on:

node-mongodb-native and nodetk are vendorized through git submodules: $ git submodule update --init

To run the tests: nodetests Please have a look at the nodetk README file to install nodetk.


This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see

Something went wrong with that request. Please try again.