meteor-astronomy icon indicating copy to clipboard operation
meteor-astronomy copied to clipboard

Possible to get current doc on Before events

Open bduff9 opened this issue 8 years ago • 1 comments

I have a schema set up where anytime someone fully completes registering (as there are 3 separate parts to it with the final being an admin approval) there are many things Mongo-side that need to be completed. I see in events where I can listen to the before save event, however the event only has the new doc in it.

I do not want to run this code every time a user is updated as it can take a little bit, however I do not see where I can check to see (based on a boolean value in the doc) whether they were not finished registering before and are now. Is this possible?

Something like the following is what I am looking for:

...
events: {
  beforeUpdate (ev) {
    if (!this.finished && ev.target.finished) doSomeWork();
  }
},
...

I know the above isn't how you would actually do it, its just for demonstration. In helpers, this points to the current doc, but in events it seems to point to the server environment. Any help would be appreciated!

bduff9 avatar Aug 03 '17 18:08 bduff9

beforeUpdate(e) {
  const doc = e.currentTarget;
  if (doc.isModified('finished') && doc.finished) {
    // Do something...
  }
}

lukejagodzinski avatar Aug 04 '17 08:08 lukejagodzinski