Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

126
Vistas
I want to fetch all the user with there created places using the vitrual populate
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

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

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) {

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda