I am having trouble understanding the use case of publish with argument.
This is what i have currently in publication
Meteor.publish('stocks', () => {
return Stocks.find();
});
and in the client side
export default createContainer((props) => {
let subscribe = Meteor.subscribe('stocks');
let stocks = [];
if (subscribe.ready()) {
console.log("subscribe,", subscribe)
stocks = Stocks.find(
{
$and: [{ History: { $exists: 1 } }, { 'History.status': { $nin: ['PROCESSED', 'COMPLETED'] } }, { $where: 'this.History.length > 0' }]
},
{ sort: { 'History.startDate': -1 } }
).fetch();
}
return {
stocks
}
}, RentalPage);
I am having a issue trying to render this page ( i am new to meteor but have completed projects in react without meteor).
There are around 2000 TOTAL stocks docs in the backend, and the query seems to take around 3-4 seconds (which i think is a lot) to Retrieve only 13 documents.
Now my question is if i use the following
Meteor.publish('stocks', (params,ctx) => {
return Stocks.find(params,ctx);
});
and in the client code:
let subscribe = Meteor.subscribe('stocks', {
$and: [{ History: { $exists: 1 } }, { 'History.status': { $nin: ['PROCESSED', 'COMPLETED'] } }, { $where: 'this.History.length > 0' }]
},
{ sort: { 'History.startDate': -1 } });
//some codes here
stocks = stock.find().fetch()
Can the server do the calculation and send me the final docs (13) and i can just use it ? or this is not a correct way to do ? i am just confused using parameters during subscription.
Any suggestions are highly appreciated