meteorhacks / search-source

Reactive Data Source for Search
MIT License
145 stars 33 forks source link

Searching a sub array and only outputting the matching data #59

Open Simranjitk opened 7 years ago

Simranjitk commented 7 years ago

I have a collection

marks {
   testers: {
        {
           "class": "math",
           "mark": 81
        },
        {
           "class": "english",
           "mark": 90
        }

    }
}

So, my server method is

SearchSource.defineSource('packages', function(searchText, options) {
    console.dir(searchText);
    if(searchText) {
      var regExp = buildRegExp(searchText);
      var options = {limit: 20};
        var selector = {"testers.class": regExp}

        return marks.find(selector, options).fetch();
      }

    } else {
        return marks.find({}, options).fetch();
    }
  });

This returns every single 'class' object if one of them matches the search query. If I search "english", I want it to just return the word 'english'. How can I do this?