Monday 12 June 2017

mongoose conditional query on populated field

I would like to run a conditional query on a populated field. Below, I have included the current query, however, I would also only like to return properties where the 'landlord.notifications === true'. The landlord as you can see below is populated from the property.

Any help appreciated:

 Property
            .find({$where: 'this.completionRate < 100', landlord: { $exists: true }})
            .populate('landlord', 'firstName lastName email notifications')



via Sachin Karia

No comments:

Post a Comment