meteor-reactive-aggregate icon indicating copy to clipboard operation
meteor-reactive-aggregate copied to clipboard

noReady functionality for publish

Open aaronthorp opened this issue 7 years ago • 1 comments

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()
    }
})

aaronthorp avatar Feb 28 '18 03:02 aaronthorp

Thanks. Please fix the one export issue and I will merge.

JcBernack avatar Feb 28 '18 12:02 JcBernack