Rishi Kc
Rishi Kc

Reputation: 95

Error message : "Unsupported projection option: match:"

I'm a newbie to node.js and mongodb. I have stored the location in my User collection as a ref to location collection. When i need to send back my response i use .populate() to send the complete data. Now i tried to filter the data with specific location using 'match' but getting the following error

"errmsg": "Unsupported projection option: match: { country: \"India\" }"

User.Find(...).populate('location_id', {
      match: { country: req.query.country}
    });

The populate works since it returns the Users with their locations if i comment out the match line. What am i missing here?

Upvotes: 1

Views: 1224

Answers (1)

Moad Ennagi
Moad Ennagi

Reputation: 1073

You need to explicitly state the path like this:
User.Find(...).populate({path: 'location_id', match: {country: req.query.country}) Also make sure to isolate india from this \"India\".

Upvotes: 2

Related Questions