Last active
August 29, 2015 14:10
-
-
Save vladimir-polyakov/69e1536d7fc468034821 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// connect to mongo | |
require('./db').init(config.mongodb, function(err) { | |
if (err) { | |
throw err; | |
} else { | |
console.log('[app] connection to mongodb has been established'); | |
// Here you can start app, this will be after db connection init... | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var Client = require('mongodb').MongoClient, | |
Collection = require('mongodbext').Collection, | |
Steppy = require('twostep').Steppy, | |
_ = require('underscore'); | |
var exports = module.exports; | |
exports.init = function(config, callback) { | |
Client.connect(config.url, function(err, db) { | |
if (err) { | |
callback(err); | |
return; | |
} | |
var usersCol = exports.users = new Collection(db, 'users'); | |
usersCol.addPlugin('sequenceId'); | |
usersCol.addPlugin('createDate'); | |
usersCol.addPlugin('updateDate'); | |
// Here you can use beforeRemove, afterRemove, beforeUpdate e.t.c. | |
usersCol.on('afterUpdate', function(params, callback) { | |
callback(); | |
}); | |
}); | |
callback(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment