snkz / mongoose-rollback Goto Github PK
View Code? Open in Web Editor NEWMongoose Rollback Machine
Mongoose Rollback Machine
I try to revert documents to a previous version which is marked by a property called _lastSavedVersion.
But when I try this:
Model.find({ edited: true }, (err, results) => {
if (err) {
next(err);
}
results.forEach((result) => {
const lastSavedVersion = result._lastSavedVersion;
result.revert(lastSavedVersion, (revertErr, hist) => {
if (revertErr) {
console.log('revert Error: ', revertErr);
next(revertErr);
}
console.log('hist: ', hist);
});
});
res.sendStatus(200);
});
}
I get an Error saying:
{
message: 'No matching document found for id "59e4756fc389a51c16f9fef3"',
name: 'VersionError'
}
Any idea what I'm doing wrong or how I can make this work?
Edit: It correctly reverts the right document in the model_hist collection. But doesn't revert the original document.
Currently delta data were stored in data like this
/* 1 */
{
"_id" : ObjectId("587a3354a185ba2f002f75df"),
"currentVersion" : 1,
"data" : [
{
"createdAt" : ISODate("2017-01-14T14:19:00.815Z"),
"_id" : ObjectId("587a3354a185ba2f002f75df"),
"_version" : 0,
"data" : "World",
"name" : "Hello"
},
{
"createdAt" : ISODate("2017-01-14T14:19:00.815Z"),
"_id" : ObjectId("587a3354a185ba2f002f75df"),
"_version" : 1,
"data" : "Yo",
"name" : "Hey",
"__v" : 0
}
],
"__v" : 0
}
Is it possible to only store changed delta data here, this jsondiffpatch may help you.
Hey,
I've been having some problems trying to get this module to work. When I don't specify a db connection when instantiating the plugin, Model.RollbackModel
returns undefined and all save()
methods on my models fail to do anything. However, if I specify in a conn
property, either as an actual connection object (in my case, I use createConnection
rather than Mongoose's global form), or as a hard coded string, I get the dreaded "Trying to open unclosed connection." error from mongoose-rollback.js:29
Any ideas?
Thanks!
Matt
Sometimes I get this error:
TypeErrornode_modules/mongoose-rollback/lib/save.js:56
TypeError · model.toObject is not a function
And this makes my server go down
Any idea about this?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.