hownowbrowncow
hownowbrowncow

Reputation: 475

Loopback.js/Node.js MongoDB - querying against an array

I have a structure that looks like this:

Model: {
  "name":"testing",
  "details":["detail1","detail2","detail10"]
}

How does one go about finding all instances where an above structure contains an instance of detail2 within their details property? I've tried:

Model.find({where:{details:{elemMatch:{"detail2"}}}},function(err,models){
    console.log(models);
    console.log(err);
});

and:

Model.find({details:"detail2"},function(err, models){
      //throws [Error: Items must be an array: "details2"]
});

Upvotes: 0

Views: 676

Answers (1)

Raymond Camden
Raymond Camden

Reputation: 10857

From what I can see (based on this comment from engineering, https://github.com/strongloop/loopback-datasource-juggler/issues/342#issuecomment-73138705), it is not possible to filter like this. You would need to get the objects and post process. In theory you could build your own remote method and do the filtering on the server so you aren't doing it server-side.

Upvotes: 1

Related Questions