Hey,
I'm currently adding some data in my afterInit event. It currently looks like this:
Posting.js
afterInit(e) {
const doc = e.currentTarget;
doc.userDoc = User.findOne({_id: doc.userId});
}
Because of some performance improvements, I want to disable the loading of the user document. I know that I can disable events via options, but there may be some other code, which still should run. So I want to create a query like this:
Posting.findOne({},{fields:{userDoc:0}});
Now the problem happens: I'm not able to get the options parameter within the afterInit event, so I'm not able to detect if I had disabled the field. After reading the documentation, I found out, that the afterFind event could help. Because it also returns the result, I could add the userDoc object if it wasn't disabled in the options. That works fine if I do a findOne(), but will fail if I do a find().fetch(), because in this case, result returns a MongoCursor instead of the result array.
So, what would be the best way to attach additional data depending on the options?
Hey,
I'm currently adding some data in my
afterInitevent. It currently looks like this:Posting.js
Because of some performance improvements, I want to disable the loading of the user document. I know that I can disable events via options, but there may be some other code, which still should run. So I want to create a query like this:
Now the problem happens: I'm not able to get the options parameter within the
afterInitevent, so I'm not able to detect if I had disabled the field. After reading the documentation, I found out, that theafterFindevent could help. Because it also returns the result, I could add the userDoc object if it wasn't disabled in the options. That works fine if I do afindOne(), but will fail if I do afind().fetch(), because in this case, result returns a MongoCursor instead of the result array.So, what would be the best way to attach additional data depending on the options?