Skip to content

Instantly share code, notes, and snippets.

@Albert-IV
Created May 5, 2014 21:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Albert-IV/5483a81917ea37ef381b to your computer and use it in GitHub Desktop.
Save Albert-IV/5483a81917ea37ef381b to your computer and use it in GitHub Desktop.
Example VersionError Fix
function saveRecord(record, args, cb) {
record.save(function(e) {
if (e && e.message == "VersionError: No matching document found.") {
recordModel.findById(record._id, function(e, newRecord) {
if(e) return cb(e);
reSaveRecord(record, newRecord, cb);
});
}
});
}
function reSaveRecord(oldRecord, newRecord, cb) {
var changedFields = oldRecord.modifiedPaths();
changedFields.forEach(function(field) {
newRecord[field] = oldRecord[field];
});
newRecord.save(cb);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment