ndx-mongo
v0.3.19
Published
Mongo database connector for ndx-framework apps
Downloads
25
Readme
ndx-mongo
mongo database connector for ndx-framework apps
Usage
npm install --save ndx-mongo
src/server/app.coffee
require 'ndx-server
dbEngine: require 'ndx-mongo'
mongoUrl: 'mongodb://192.168.99.100:27017/test'
tables: ['users', 'table1', 'table2']
.start()
Environment variables
mongoUrl can be set with the environment variable MONGO_URL
Methods
db.select(string table, object whereObj, function callback)
Select data
db.insert(string table, object insertObj, function callback)
Insert data
db.update(string table, object updateObj, object whereObj, function callback)
Update data
db.upsert(string table, object upsertObj, object whereObj, function callback)
Upsert data
db.delete(string table, object whereObj, function callback)
Delete data
db.exec(string sql, array props, bool notCritical) -> data
Callbacks
ndx.database.on 'callbackName', (args, cb) ->
#do something with args
cb true #or false if you want to cancel the operation
ready
The database is ready to use
preInsert
args.table
The database table being operated onargs.obj
The object being inserted into the databaseargs.user
The user carrying out the operation
cb(false)
to cancel the insert
insert
args.id
The inserted object's idargs.table
The database table being operated onargs.obj
The object that was inserted into the databaseargs.user
The user carrying out the operation
preUpdate
args.id
The id of the object being updatedargs.table
The database table being operated onargs.where
The database queryargs.obj
The data to updateargs.oldObj
The value of the object preUpdateargs.changes
The changes to be appliedargs.user
The user carrying out the operation
cb(false)
to cancel the update
update
args.id
The id of the object that was updatedargs.table
The database table that was operated onargs.obj
The data that was updatedargs.oldObj
The value of the object pre updateargs.newObj
The value of the object post updateargs.changes
The changes that were appliedargs.user
The user carrying out the operation
preSelect
args.table
The database table being operated onargs.args
The arguments that were passed to the select functionargs.user
The user carrying out the operation
cb(false)
to cancel the select
select
args.table
The database table being operated onargs.objs
The objects that were selected from the databaseargs.user
The user carrying out the operation
preDelete
args.table
The database table being operated onargs.where
The database queryargs.user
The user carrying out the operation
cb(false)
to cancel the delete
delete
args.table
The database table being operated onargs.user
The user carrying out the operation
callbacks can be used to modify data flowing to and from the database.
see ndx-permissions and ndx-profiler for examles
db.off(string callbackName, function callback) -> db
Unregister a callback