meteor-reactive-aggregate
meteor-reactive-aggregate copied to clipboard
noReady functionality for publish
Added noReady: true option to options variable allowing optional ready state to allow for in-publish aggregation similar to tmeasday:publish-counts.
Example use: eCommerce store listing products, aggregation to get distinct brand field for filtering using the existing search keywords or product category/other filters selected.
Also modified export to default export to allow for use of
import ReactiveAggregate from 'meteor/jcbernack:reactive-aggregate'
instead of
import { ReactiveAggregate } from 'meteor/jcbernack:reactive-aggregate'
as there are no other variables for importing from this package.
Meteor.publish('search', function(query, limit, skip) {
let filter = _buildSearchQuery(query.keyword)
var data = Products.find(filter, {limit, skip})
Meteor.defer(() => {
ReactiveAggregate(this, Products, [
{ $match: filter },
{ $group: { _id: '$brand', count: { $sum: 1 } } }
], { clientCollection: 'filterBrand', noReady: true })
ReactiveAggregate(this, Products, [
{ $match: filter },
{ $group: { _id: '$category_id', count: { $sum: 1 } } }
], { clientCollection: 'filterCategories', noReady: true })
})
Counts.publish(this, "searchCount", Products.find(filter), {noReady: true})
return data
} else {
this.stop()
}
})
Thanks. Please fix the one export issue and I will merge.