Coder Social home page Coder Social logo

meteor-vermongo's Introduction

Meteor Vermongo

Implementing Vermongo: https://github.com/thiloplanz/v7files/wiki/Vermongo

Github: https://github.com/micktaiwan/meteor-vermongo/

AtmosphereJS: https://atmospherejs.com/mickaelfm/vermongo

Report bugs or suggestions: https://github.com/micktaiwan/meteor-vermongo/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

    Requirements = new Mongo.Collection('requirements').vermongo({timestamps: true, userId: 'modifierId', ignoredFields: ['rank']});

    Template.requirements.onCreated(function() {

      var _id = Requirements.insert({title: "new insert with default value"});
      Requirements.update({ _id }, {$set:{title: "updated with new value !"}});

    });

    Template.requirements.helpers({

      requirements: function() {
        return Requirements.find();
      },

    });
    <body>
      <h1>Welcome to Meteor!</h1>

      <button class="js-new">New</button>
      {{> requirements}}

    </body>

    <template name="requirements">
      <ul>
        {{#each requirements}}
        {{> req }}
        {{/each}}
      </ul>
    </template>

    <template name="req">
      <li>{{title}} - {{modifiedAt}} - version: {{_version}}</li>
      <ul>
        {{#each versions}}
        {{> version }}
        {{/each}}
      </ul>
    </template>

    <template name="version">
      <li>{{title}} - {{modifiedAt}} - version: {{_version}}</li>
    </template>

A new collection "mycollection.vermongo" will be created for each versioned collection and will store old document versions.

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

meteor-vermongo's People

Contributors

micktaiwan avatar s7dhansh avatar

Stargazers

 avatar Mathias Hoffmann avatar G avatar larabuli avatar Theodor Diaconu avatar Oleg Krasavin avatar  avatar Jorge Fernández avatar Jose Hilario Almeida avatar Jan Hendrik Mangold avatar Alexandre Alonso avatar Mitar avatar Martin avatar  avatar Andżelo avatar David Patte avatar  avatar Robin Jakobsson avatar Marvin Villanueva avatar  avatar

Watchers

 avatar Martin avatar David Patte avatar

meteor-vermongo's Issues

for (... in ...) {} modified when mickaelfm:vermongo is installed (meteor 1.2.x).

Hi Mickael,

I have an issue using vermongo (with meteor 1.2.x, I don't verify with older meteor release).

WIthout vermongo (1.1.3) in my project, if I use for (... in ...) {} , I got (on client or server side) :

l = [ 1 , 2 ]
[1, 2]
for ( x in l ) { console.log( x ) }
0
1

With vermongo (1.1.3) installed in my project, I got :

l = [ 1 , 2 ]
[1, 2]
for ( x in l ) { console.log( x ) }
0
1
diff
equals

Others packages using for (... in ...) {} are broken.

I'm not sure to understand but I think this issue should by linked to #2.

Thanks for your help.

Have a nice day.

Philippe

Feedback for enhancement

Hi,

I've been using this package for a few weeks now and I think it is the most comprehensive one that's available. So kudos for developing it!

I have significant experience (coming from the java world with solid orm layers like hibernate and spring data) with versioning and atomic updates.

I'd like to chip in, if you don't mind, and share some feedback. In fact, if we can agree on these, I may even be able to contribute with PR's.

So here they are:

  • The vermongo collection and its first document should be created at insert
  • Modified timestamp should not be added on insert
  • Both the existence and the names of timestamp fields (createdAt, createdBy, modifiedAt, modifiedBy) should be configurable
  • A global vermongo configuration option should be provided
  • An atomic find and modify option should be available
  • Before update hook should analyze the modifier to derive the field names, instead of relying on the provided field names so that we can compare nested fields instead of just top level fields
  • A collection.fetchVersion(_v) method should be available to gain direct access to versions
  • A collection.restoreVersion(_v) method should be available to revert to versions
  • A new orm layer called astronomy is picking up pace and adoption. Perhaps we can support that, too.

So, what do you think? Would you like to discuss and possibly work together on implementing these?

update() gets stuck on TypeError

Hi,

I want to use Vermongo in Meteor and tried out your package, but following the Usage guide (HTML is run on Client only) I got stuck on the following error when running the app:

Uncaught TypeError: fieldNames.diff is not a function(anonymous function) @ vermongo.js:49(anonymous function) @ update.js:42_.each..forEach @ underscore.js:105(anonymous function) @ update.js:41.each..forEach @ underscore.js:105(anonymous function) @ update.js:40CollectionHooks.extendCollectionInstance..each.collection.(anonymous function) @ collection-hooks.js:103(anonymous function) @ VM78234:2InjectedScript._evaluateOn @ VM78075:883InjectedScript._evaluateAndWrap @ VM78075:816InjectedScript.evaluate @ VM78075:682

This is caused by Requirements.update({_id: id}, {$set:{title: "updated with new value !"}}); and seems to be related to a recent commit 0e9ebfa of yours. Do you know how to fix this? If I comment out the update command the tutorial appears to run fine.

Thanks in advance,

vermongo disables _.isEqual() (underscore)

In my code immediately after doing a accountSchema.clean({$set:newFields},{isModifier:true}) and before doing a mongo insert I am doing a compare using _.isEqual(this,newFields).

It works fine without vermongo running attched to the collection, but fails to detect equality if vermongo is active.

I suspect some action in vermongo is modifying the prototypes of newFields preventing equality?

Versions are created for unsuccessful updates

If the collection2/simpleschema validations don't succeed, there are edge cases where update fails but copyDoc(doc) goes through with creating a version.

I think the insert happening on a server only method might be the culprit, I'm not sure. Furthermore, I've witnessed this situation with the users collection. This may or may not also be related to presence of ignored fields.

This needs to be further tested, however, a safeguard would be to convert copyDoc to a Meteor.method which automatically generates client stubs, so would be less likely to cause race conditions where client and server validation results differ.

offOnce and historical records

I need to do a schema change on a collection and its vermongo history collection.

What it the process to disable doing a new version when I update a record, and what is the process to update a .vermongo (historical) record?

Conflict between Vermongo and Collection2

I have a collection that has autoFields using Collection2. These autofields are 'updated' (a date), and 'lastEditor' (a userId). When creating or editing records in the collection these are filled in automatically by collection2.

I am using vermongo for the collection, but not using your timestamp or userId options, as they would obviously be redundant.

Everything works fine, except in the case of delete, where updated and lastEditor are not set by collection2 to the time of the delete and user that performed the delete, nor are they set by vermongo since I have those options off (and they use different fieldnames).

What would you suggest is my best way of handling this scenario?

Should I fork a copy of vermongo to handle the delete case, or are there hooks you would recommend I could use to set the 'lastEditor' and 'updated' at the time of delete?

Increased CPU usage

Including the package causes a CPU usage of 100%. Is this normal? Or else, I will drill it down and attach a simple example to reproduce.

Uncaught TypeError: fieldNames.diff(...).equals is not a function(anonymous function) @ vermongo.js:56

Hello Mick,

Similar issue to #1
Array.prototype.equals is not defined in the package level. You should already have it in your project level. I defined it as below from http://stackoverflow.com/questions/7837456/comparing-two-arrays-in-javascript/14853974#14853974

Regards

//attach the .equals method to Array's prototype to call it on any array
if (!Array.prototype.equals) {
  Array.prototype.equals = function (array) {
    // if the other array is a falsy value, return
    if (!array)
      return false;

    // compare lengths - can save a lot of time
    if (this.length != array.length)
      return false;

    for (var i = 0, l = this.length; i < l; i++) {
      // Check if we have nested arrays
      if (this[i] instanceof Array && array[i] instanceof Array) {
        // recurse into the nested arrays
        if (!this[i].equals(array[i]))
          return false;
      }
      else if (this[i] != array[i]) {
        // Warning - two different object instances will never be equal: {x:20} != {x:20}
        return false;
      }
    }
    return true;
  }
}

Sample implementation on a simple form

Hi Mick,

Thanks for this great package! 👍

I would love to see an example implementation on a simple form, something like insert data then update this.data, then the _version thru select > option and it will automatically iterate the version number every time the document is updated, then, if a user select a certain version it displays the data of that version.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.