I have a problem in my Nodejs project with Mongoose as the ORM. I am logging some requests between the client and the server. When I receive a response from a client, I issue another request, and from time to time I get a VersionError: No matching document found in Mongoose.
This is caused by the versioning system in Mongoose, as explained here: Versioning in Mongoose.
So, I'd really like to follow his advice and do something like this:
ExampleSchema.methods.update_doc = function(callback) {
this.save(function(err, video) {
if(err) {
if(err instanceof mongoose.Error.VersionError) {
reload mongoose document and repeat save process
}
callback.call(self, err);
} else {
callback.call(self, null);
}
});
}
But how can I reload the document inside the object method?