Consider the scenario below:
In my client application, I have created a complex filter stored in a custom reactive object named currentFilter
.
The method currentFilter.buildQuery()
is used to generate the query object for MongoDB database.
Due to the large volume of data stored in the MongoDB database on the server, I prefer to perform data filtering on the server side and only send relevant data to the client.
Here is the code snippet:
//CLIENT
// file = a.html
<template name="myTemplate">
{{data}}
</template>
//file = a.js
cbs = new Mongo.Collection('cbsLoc');
Template.myTemplate.helpers({
data: function () {
Tracker.autorun(function () {
Meteor.subscribe('cbsLoc',currentFilter.buildQuery())
});
return cbs.find() // (a)
}
})
//SERVER
Meteor.publish('cbsLoc', function(filter) {
return cbs.find(filter)
});
The cbs.find()
retrieves data to populate a table. Unfortunately, it doesn't show any data. Although the data is sent to the client, it's not being displayed in the DOM.
However, if I modify line (a)
to cbs.find().fetch()
, it works perfectly fine and displays the data in the DOM.
I would greatly appreciate any assistance with this issue.