Isomorphic library, which allows you to use Mongoose.js models remotely from your frontend in a framework agnostic fashion


isomorphic client side library and server framework, which brings Mongoose model to the browser(or over the network to other node process). Based on Framework agnostic-usable with any framework-let it be Angular, Aurelia, React or any other.

On top of that, it features live queries. These are performance hungry, but Moonridge is caching live queries in memory, so that one query is being live checked only once. If one user runs the same query as another, they are hitting the DB only once.

See examples in smoke test folder(Angular|React|Aurelia), if still not sufficent, read source code. Better docs are planned/WIP.

    var mongoose = require('mongoose');
    var Moonridge = require('moonridge');
    var MR = moonridge(mongoose, "mongodb://localhost/moonridge_showcase");     //MongoDB address is optional-you can connect as always with mongoose 
    var bookModel = MR.model('book', {  //mongoose schema defintion 
            name: String,
            author: String
        }, {
             schemaInitfunction (schema) {
                // makes sure only one book per nameXauthor exists 
                schema.index({ name: 1, author: 1 }, { unique: true, dropDups: true });
    MR.bootstrap(app);  //app is your express app, Moonridge will start listening on port app.get("port") 
    var Moonridge = require('moonridge-client');
    //Moonridge backend 
    var mr = Moonridge({url: 'http://localhost:8080', hs: {query: 'nick=testUser'}});
    var fighterModel = mr.model('fighter');
    //live query 
    var LQ = fighterModel.liveQuery().sort('health').exec();
      LQ.result; //has a result of the query-array or a number 
      //query is live now 
    //create a new entity 
    fighterModel.create({name: 'Arya', health: 50}).then(function(created){
      console.log('created a fighter: ', created);
      //LQ.result now also contains Arya = 49;
      //update an entity 
        //remove it from DB 

Also you need to connect to your backend-Moonridge uses a promise resolution for this. See how in the included smoketest

All server-client communication is done with -another project of mine, so errors are propagated for all server-side calls which return an error(or reject their promise). This is especially helpful with schema validation errors.

Internet Explorer 8+ - though it needs es5shim
Safari 4+
Google Chrome 4+
Firefox 4+
Opera 10.61+
iPhone Safari
iPad Safari
Android WebKit
WebOs WebKit

One could ask why not just port mongoosejs to the client side and let clients talk to mongo directly. While this would surely be an interesting project, Moonridge has features which would not be possible without a server instance(live querying, custom authorization/authentication). I think these features are worth it introducing a new framework to the backend.

Every client liveQuery is serialized and sent via to backend. Backend parses it and constructs real mongoose query, wich is immediately run(if it doesn't exist already in server memory). The return is sent back to client. Any change to a certain document (creation, deletion, update) is checked again for all in-memory queries. MongoDB checks just one recently changed document, not the whole query, so it should be pretty quick. If query is satisfied, the changed document is propagated to listening clients. And that is basically it.

Pull requests are welcome and same goes for issues!