Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible to get current doc on Before events #637

Open
bduff9 opened this issue Aug 3, 2017 · 1 comment
Open

Possible to get current doc on Before events #637

bduff9 opened this issue Aug 3, 2017 · 1 comment

Comments

@bduff9
Copy link

bduff9 commented Aug 3, 2017

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!

@lukejagodzinski
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants