Meteor Vermongo
Implementing Vermongo: https://github.com/thiloplanz/v7files/wiki/Vermongo
Github: Forked from https://github.com/micktaiwan/meteor-vermongo/
AtmosphereJS: https://atmospherejs.com/settlin/vermongo
Report bugs or suggestions: https://github.com/settlin/monorepo/issues
Currently provides
- automatic versioning of collection documents, including removal
- helper to access old versions of documents
- option for automatic timestamping
- option for automatic userId logging
- option for ignoring some updated fields
Usage
1 Requirements = new Mongo.Collection('requirements').vermongo({timestamps: true, userId: 'modifierId', ignoredFields: ['rank']}); 2 3 Template.requirements.onCreated(function() { 4 5 var id = Requirements.insert({title: "new insert with default value"}); 6 Requirements.update({_id: id}, {$set:{title: "updated with new value !"}}); 7 8 }); 9 10 Template.requirements.helpers({ 11 12 requirements: function() { 13 return Requirements.find(); 14 }, 15 16 });
1 <body> 2 <h1>Welcome to Meteor!</h1> 3 4 <button class="js-new">New</button> 5 {{> requirements}} 6 7 </body> 8 9 <template name="requirements"> 10 <ul> 11 {{#each requirements}} 12 {{> req }} 13 {{/each}} 14 </ul> 15 </template> 16 17 <template name="req"> 18 <li>{{title}} - {{modifiedAt}} - version: {{_version}}</li> 19 <ul> 20 {{#each versions}} 21 {{> version }} 22 {{/each}} 23 </ul> 24 </template> 25 26 <template name="version"> 27 <li>{{title}} - {{modifiedAt}} - version: {{_version}}</li> 28 </template>
A new collection "mycollection.vermongo" will be created for each versioned collection and will store old document versions.
You can change the name of the collection by passing a collectionName
option to the vermongo function.
A collection helper "versions" is created to access old versions of the document.
On document removal, the current version is saved into the vermongo collection, and then a dummy new version is added with a special flag (as a column "_deleted" that equals to true).
TODO
- Unit tests :)
- undo helper