Hi, I have thousands of Mongo documents and I need to show its list (or just what does belong to a logged on user), and also need to show full document details just for a selected item (all is on one page with two templates). Publishing all details makes the loading time about 4 times longer on localhost (2s vs 8s), so I want to limit data that are returned to the client.
While this reduces the loading time (not publishing “events”), I don’t know how to publish all details for a selected animal.
Meteor.publish('animals', function () {
if (Meteor.user()) {
return Animals.find({ farm : Meteor.user().farm }, { fields: { name: 1, farm: 1 } });
}
});
I can subscribe to this, but the other data is not there.
Meteor.publish('animalDetail', function(name) {
if (Meteor.user()) {
return Animals.findOne({farm: Meteor.user().farm, name: name})
}
})
Meteor.subscribe('animals');
Meteor.subscribe('animalDetails', Session.get('whichAnimal'));
While the full list shows ok, the details won’t show anything (unless I also publish the attribute called “events”). I use the events array to render a nicely formatted list of events
Template.animalDetails.helpers({
events() {
if (Session.get('whichAnimal')) {
let events = Animals.findOne(Session.get('whichAnimal')).events.map( (o) => { ...
I tried some experiments with
Template.animalDetails.onCreated(function() {
this.autorun(() => {
this.subscribe('animalDetails', Session.get('whichAnimal'));
But that doesn’t work (and I don’t really understand how that works).
Can you please tell me how to achieve that or if there is a good source of information for all those Tracker events, autorun, onCreated and onRendered and especially how to combine it together?
Thank you