Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

124
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda