{"id":13480733,"url":"https://github.com/capaj/Moonridge","last_synced_at":"2025-03-27T11:30:54.793Z","repository":{"id":10863936,"uuid":"13149130","full_name":"capaj/Moonridge","owner":"capaj","description":"Mongo live query framework bootstrapped on socket.io-rpc and mongoosejs. Takes your mongoose models and allows for easy and elegant consumption over the network in your frontend app or in remote node process.","archived":false,"fork":false,"pushed_at":"2017-04-17T08:37:42.000Z","size":6811,"stargazers_count":66,"open_issues_count":8,"forks_count":8,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-18T21:50:37.814Z","etag":null,"topics":["mongoosejs","realtime-database","socket-io"],"latest_commit_sha":null,"homepage":"http://capaj.github.io/Moonridge","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/capaj.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-09-27T11:48:30.000Z","updated_at":"2024-01-27T19:44:41.000Z","dependencies_parsed_at":"2022-08-29T20:30:43.103Z","dependency_job_id":null,"html_url":"https://github.com/capaj/Moonridge","commit_stats":null,"previous_names":[],"tags_count":33,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/capaj%2FMoonridge","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/capaj%2FMoonridge/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/capaj%2FMoonridge/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/capaj%2FMoonridge/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/capaj","download_url":"https://codeload.github.com/capaj/Moonridge/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245835943,"owners_count":20680296,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["mongoosejs","realtime-database","socket-io"],"created_at":"2024-07-31T17:00:44.353Z","updated_at":"2025-03-27T11:30:54.449Z","avatar_url":"https://github.com/capaj.png","language":"JavaScript","funding_links":[],"categories":["Libraries"],"sub_categories":["JavaScript"],"readme":"## Deprecated notice\nI don't maintain this anymore, so use only if you're willing to fix bugs yourself.\n\nMoonridge    [![Build Status](https://travis-ci.org/capaj/Moonridge.svg?tag=1.0.3)](https://travis-ci.org/capaj/Moonridge) [![Dependency Status](https://david-dm.org/capaj/Moonridge.svg)](https://david-dm.org/capaj/Moonridge)\n=========\n[![NPM badge](https://nodei.co/npm/moonridge.png?downloads=true\u0026downloadRank=true\u0026stars=true)](https://nodei.co/npm/moonridge/)\n\nisomorphic [client side library](https://github.com/capaj/Moonridge-client) and server framework, which brings Mongoose model to the browser(or over the network to other node process). Based on [socket.io-rpc](https://github.com/capaj/socket.io-rpc). Framework agnostic-usable with anything-let it be Angular, Aurelia, React or any other.\n\n\nProbably the coolest feature is 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 10000 users run the same query, the DB performance performs the same amount of operations as if one user was accessing it. So your DB should be under the same load no matter how many people use your web app(presuming they are not writing into the DB).\n\n## Install\n```\nnpm i moonridge -S\n```\n\n### How to use it?\n[Serverside API](https://github.com/capaj/Moonridge/wiki/API) is quite straightforward, if still not sufficent, read source code of examples.\n\nin smoke test folder([Angular](test/e2e-smoketest/angular)|[React](test/e2e-smoketest/react)|[Aurelia](test/e2e-smoketest/aurelia)), \n\n## Basic usage serverside\n```javascript\n    var MR = require('moonridge')\n\n\tMR.connect(\"mongodb://localhost/moonridge_showcase\") //MongoDB address is optional-you can connect as always with mongoose\n\tvar mongoose = MR.mongoose\n    var bookModel = MR.model('book', {  //mongoose schema definition\n            name: String,\n            author: String\n        }, {\n             schemaInit: function (schema) {\n                // makes sure only one book per nameXauthor exists\n                schema.index({ name: 1, author: 1 }, { unique: true, dropDups: true });\n            }\n        })\n    ...\n    var app = require('express')()\n    var server = require('http').Server(app)\n    //bookModel is an extended mongoose model, so if you know how to work with mongoose models, you'll be right at home\n    MR.bootstrap(server) \n    app.use('/api', MR.baucis()) // gives your REST api for your DB in case you need it alongside to socket.io API\n    server.listen(port, () =\u003e {\n          app.emit('listening')\n          console.log('started listening on ' + port, ' in ', env, new Date())\n    })\n```\n## On the CLIENT:\n```javascript\n   \tvar Moonridge = require('moonridge-client')\n\t//Moonridge backend\n\tvar mr = Moonridge({url: 'http://localhost:8080', hs: {query: 'nick=testUser'}})\n\tvar fighterModel = mr.model('fighter')\n\t//live query\n\tvar LQ = fighterModel.liveQuery().sort('health').exec()\n\n\tLQ.promise.then(function(){\n\t  LQ.result //has a result of the query-array or a number\n\t  //query is live now\n\t});\n\t//create a new entity\n\tfighterModel.create({name: 'Arya', health: 50}).then(function(created){\n\t  console.log('created a fighter: ', created)\n\t  //LQ.result now also contains Arya\n\t  created.health = 49\n\t  //update an entity\n\t  fighterModel.update(created).then(function () {\n  \t    //remove it from DB\n  \t    fighterModel.remove(created)\n\t  });\n\t});\n```    \nAlso you need to connect to your backend-just pass a simple object with url property like [HERE](https://github.com/capaj/Moonridge/blob/master/test/e2e-smoketest/react/Fighters.jsx#L7).\n\nThe whole client side api for queries shadows the [Mongoose query API](http://mongoosejs.com/docs/api.html#query-js).\n\n## Errorhandling\n\nAll server-client communication is done with [socket.io-rpc](https://github.com/capaj/socket.io-rpc)-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, where backend tells the frontend exactly what failed.\n\n## Supported browsers\n### Desktop\n    Internet Explorer 8+ - though it needs es5shim\n    Safari 4+\n    Google Chrome 4+\n    Firefox 4+\n    Opera 10.61+\n### Mobile\n    iPhone Safari\n    iPad Safari\n    Android WebKit\n    WebOs WebKit\n\n### Why not just a ported mongoosejs on the client side?\nOne 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.\n\n## How does live querying work in one paragraph\nEvery client liveQuery is serialized and sent via socket.io to backend. Backend parses it and constructs real mongoose query, which 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.\n\n## But mongoDB doesn't have JOINs!\nYes I know and if you need joins, you better look for something else. Moonridge is tailored for web apps which do a lot of small and custom queries. Basically you would want to save any bit of bandwith and show pieces of data in your app as soon as possible, you are best served using Moonridge.\n\n## Production samples\nI have few production apps running on moonrige, feel free to take a peek how moonridge is used:\n\n - [sbirejto.cz](https://github.com/capaj/postuj-hovna)\n\nPull requests are welcome and same goes for issues!\n[![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcapaj%2FMoonridge","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcapaj%2FMoonridge","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcapaj%2FMoonridge/lists"}