Skip to content

Instantly share code, notes, and snippets.

@aheckmann
Created January 31, 2012 17:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save aheckmann/1711749 to your computer and use it in GitHub Desktop.
Save aheckmann/1711749 to your computer and use it in GitHub Desktop.
var mongoose = require('mongoose');
mongoose.connect('localhost', 'testing_invalidate');
var schema = new mongoose.Schema({
name: String
});
schema.methods.do = function (v) {
this.invalidate('name', new Error('nope'));
}
var A = mongoose.model('A', schema);
mongoose.connection.on('open', function () {
A.create({ name: 'iphone' }, function (err, a) {
if (err) return console.error(err.stack||err);
A.findById(a._id, function (err, doc) {
if (err) return console.error(err.stack||err);
doc.do();
doc.save(function (err) {
if (err) console.error('got error', err.stack||err);
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