Hi guys,
I am searching for using the $lookup in meteor. I know i can only use it on server end but i want this within helper to get the reactivity of meteor in case on of the tables data changes. But using it in helper would not let me get data from sevrer end as i cant user Meteor.call inside helper. So what can i do ?
Am i doing something wrong(or may be entirely wrong iabout sing these helpers ) ? The idea is to use join in Meteor js.
Thanks in advance for anyone going to put any sort of effort.
There’s really no performant way to to this solely on the client with minimongo
, but if all you want is the ability to subscribe to reactive aggregations (which is where $lookup
is used), you can just make use of one of the reactive aggregation packages, for example tunguska:reactive-aggregate
or jcbernack:reactive-aggregate
.
1 Like
But even with these packages, i can only use it on server end. I want to use them inside helpers. Is there any way to use them with helper reactivity ?
Those packages are to allow you to use reactive aggregations from the client - including in helpers. They work just like normal publications as far the client is concerned.
ok will try them and see if they are of some help.
tunguska:reactive-aggregate
i just viewed this one. As far as i understood, we can publish aggrestion on server and then subscribe it normally on client like always.
import { Mongo } from 'meteor/mongo';
// Define a named, client-only collection, matching the publication's clientCollection.
const clientReport = new Mongo.Collection('clientReport');
Template.statsBrief.onCreated(function() {
// subscribe to the aggregation
this.subscribe('reportTotals');
// Then in our Template helper:
Template.statsBrief.helpers({
reportTotals() {
return clientReport.find();
},
});
but how do i use it with $lookup ? i can publish it from server how do i use it on client.
like here i am fetching from one collection only.
Template.statsBrief.helpers({
reportTotals() {
return clientReport.find();
},
});
what can i do now ?
Your aggregation pipeline (including your $lookup
operations) goes on the server. You subscribe on the client. Any changes to the collection(s) you’re aggregating over cause the (new) aggregation results to be immediately published to the client.
If you want to change the query from the client, use reactive parameters in the subscription exactly as you would normally do.
You could also consider a different approach entirely, by using cultofcoders:grapher
, although the principle is the same - it runs on the server and delivers results to the client.
1 Like