Skip to content

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

@Simranjitk

Description

@Simranjitk

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions