samjs-mongo
adds a model and interface to connect with mongoDB.
Client: samjs-mongo-client
Getting Started
npm install --save samjs-mongonpm install --save-dev samjs-mongo-client
Usage
// server-sidesamjspluginsoptions // will be in config mode after startup to setup the mongo connection// after successsful configuration:samjsstateonceStarted //client in browser samjspluginsrequire "samjs-mongo-client" // when mongoURI isn't setted in config, samjs will go into// install mode, there you can set itsamjsinstall var someModel = "someModel"// has insert / count / find / update / removesomeModel // in another client events: inserted / updated / removedsomeModel
model props
name | type | default | description |
---|---|---|---|
schema | object or factory function | - | (required) mongoose schema |
model hooks
each hook has to return its arguments.
name | arguments | description |
---|---|---|
beforeFind | {query, client} |
will be called before each find and count |
afterFind | results |
will be called after each find and count |
beforeInsert | {query, client} |
will be called before each insert |
afterInsert | results |
will be called after each insert |
beforeUpdate | {query, client} |
will be called before each server-side update |
afterUpdate | results |
will be called after each server-side update |
beforeRemove | {query, client} |
will be called before each server-side remove |
afterRemove | results |
will be called after each server-side remove |
beforeCreate | model |
will be called before model creation |
afterCreate | model |
will be called after model creation |
example:
samjspluginsoptions
plugins
plugins are activated on model level
samjspluginsoptions