const getAllUsers = async (req, res) => {
try {
await User.find({}).populate('place').exec(function(error, data) {
console.log(data.places)
console.log(data)
res.json("ok")
});
} catch (error) {
console.log(error)
res.status(500).send(error)
}
}
the virtual define for user is this.
userSchema.virtual('places',{
ref: "Place",
localField: "id",
foreignField: "creator",
})
when i use findById for one user it work but when i use find it's not working
the problem is the name of the virtual are not the same. place != places
as far as i can see in the docs here: the names should be the same https://mongoosejs.com/docs/populate.html
await User.find({}).populate('place').exec(function(error, data) {
need to be changed to :
await User.find({}).populate('places').exec(function(error, data) {