matteodem / meteor-easy-search

Easy-to-use search for Meteor with Blaze Components
MIT License
438 stars 68 forks source link

How to filter published collection fields #579

Closed TechplexEngineer closed 7 years ago

TechplexEngineer commented 7 years ago

Is there an easy way, hopefully one that I am missing, to limit the fields being published when using easy search with the mongodb engine?

I can manipulate the selector but all of the fields in the document are still returned.

TechplexEngineer commented 7 years ago

Turns out what I was looking for was the fields option to the EasySearch.MongoDB engine.

http://matteodem.github.io/meteor-easy-search/docs/engines/#configuration

export default new EasySearch.Index({
    collection: QA, //the collection to operate on
    //the fields to search
    fields: ['title', 'question', 'published.answer'],
    engine: new EasySearch.MongoDB({
        // ...
        fields(searchObject, options)
        {
            //the fields to publish
            return {question: 1, title: 1};
        },
        // ...
    }),
});