Skip to content

Instantly share code, notes, and snippets.

@jroes
Forked from aheckmann/saveorder.js
Created June 27, 2012 17:52
Show Gist options
  • Save jroes/3005679 to your computer and use it in GitHub Desktop.
Save jroes/3005679 to your computer and use it in GitHub Desktop.
var mongoose = require('./../mongoose');
console.error(
'\n==========='
, ' mongoose version: '
, mongoose.version
, '========\n\n'
);
var Schema = mongoose.Schema;
mongoose.connect('localhost', 'testing_saveorder');
mongoose.connection.on('error', function () {
console.error(arguments);
});
var schema = new Schema({
name: String
});
schema.pre('save', function (next) {
console.error('pre save');
next();
});
schema.post('save', function () {
console.error('post save start');
A.update({}, {name: 'b'}, function(err, numAffected) {
if (err) {
console.error(err);
return;
}
console.error('post save end', numAffected);
return;
});
});
var A = mongoose.model('A', schema);
mongoose.connection.on('open', function () {
var a = new A({ name: 'saveorder' });
a.save(function (err, a) {
console.error('save callback');
mongoose.connection.db.dropDatabase(function () {
mongoose.connection.close();
});
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment