Using aggregate result in the observer query? #59
Falkovic1993
started this conversation in
General
Replies: 1 comment 3 replies
-
Hi @Falkovic1993 - glad you're finding the package useful 🙂 I'm not sure I understand well enough to comment. However:
Isn't it just a case of ensuring that the |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey Rob,
Thanks for the package, works really well 👍
I have a question regarding performance optimizing, when using the reactive aggregate to lookup in another collection would it be possible to use the result of the aggregate in the observer if you have multiple observers? See example here;
ReactiveAggregate( this, Bookings, [ { $match: { restaurantId, dateTime: { $gte: fromDateTime, $lt: toDateTime }, }, }, { $lookup: { from: 'Customers', localField: 'customerId', foreignField: '_id', as: 'customer', }, }, { $unwind: '$customer' }, { $project: neededBookingFields }, ], { noAutomaticObserver: true, debounceCount: 100, debounceDelay: 100, observers: [Bookings.find(query), Customers.find({ restaurantId })] } );
Since we want to observe both our bookings as well as the customers, it would make sense to only observe those customers who are matching the bookings. In our example, we save our customerId on the bookings. So let's say we're looking at a day with 10 bookings, the maximum customers we should observe would be the same or less, but instead, we observing all customers, which is not optimal in the long run :-)
Hope it makes sense, else let me know if I should elaborate a bit more.
Cheers
Beta Was this translation helpful? Give feedback.
All reactions