How to query by reference field

I have 2 mongo schemas :

User :

{
  _id: ObjectId,
  name: String,
  country: ObjectId // Reference to schema Country
}

Country:

{
  _id: ObjectId,
  name: String
}

I want to get all users have country name is VietNam.

What the query (only query to User) I can use for this case ??

I wanna look like this SQL Query:

SELECT * 
FROM User
JOIN Country 
ON User.country = Country._id 
WHERE Country.name = VietNam


#javascript #node-js #mongodb

4 Likes1.70 GEEK