Skip to content
Jiri Spac edited this page Mar 30, 2016 · 3 revisions

Obtain Moonridge singleton by simply requireing it:

const moonridge = require('moonridge)'

Moonridge singleton API

connect()

@param {String} connString to mongoDB
@param {Object} opts connection options
@returns {{model: regNewModel, userModel: registerUserModel, authUser: authUser, bootstrap: createServer}} moonridge
instance which allows to register models and bootstrap itself

userModel()

@param schemaExtend
@param {Object} opts
@returns {MRModel}

user model is special compared to all other models in that it doesn't have an owner. This method should only be called once at runtime.

model()

@param {String} name
@param {Object} schema
@param {Object} opts
@param {Function} [opts.checkPermission] function which should return true/false depending if the connected socket has/hasn't priviliges
@param {Object} [opts.permissions] with 4 properties: 'C', 'R','U', 'D' which each represents one type of operation,
                                 values should be numbers indicating which level of privilige is needed
@param {queryMiddleware} [opts.queryMiddleware] an array of middleware functions which you can utilize to manipulate the query every time before moonridge runs any for this model
@returns {MRModel}

every model has an owner field. This contains an _id of an owner.

bootstrap()

Shares the same signature as express.js listen method, because it passes arguments to it
@param {Number} port
@param {String} [hostname]
@param {Function} [Callback]
@returns {{rpcNsp: (Emitter), io: {Object}, server: http.Server}}

models

is a hashobject with references to all defined models. Indexed by the model name.

mongoose

is a mongoose instance for your needs like

baucis

baucis instance

Clone this wiki locally