Created
January 31, 2012 17:33
-
-
Save aheckmann/1711749 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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