Sidney
Sidney

Reputation: 141

Can I use the sails's query modifier "contains" with a collection of objects?

I'm trying to obtain all objects that have an especific object in a collection. Example:

Object Company has a collection of Employees, and I want to find all Companies who have a especific Employee on this collection. What I'm trying to do is:

Company.find({where:{employees: {contains: employeeX}}}, function (err, companies) {
  ...
});

But it's not working.

Upvotes: 0

Views: 295

Answers (1)

Abhishek
Abhishek

Reputation: 2019

var criteria = { "employees":{$in: [{employeeId:employeeXId}]}};     

User
   .find(criteria)  
   .then(function(data){
      //Employee Collection
   })  

This works for me

Upvotes: 1

Related Questions