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

86
Visualizações
mongoose populate for array of ref
  • I have Booking model with field [status(type:String)] and can only have four values NEW,ALLOTED,CANCELLED,COMPLETED . And also I have Customer model ,which has field [bookings(as array of Booking ("ref"))]

  • Actually I need four arrays for four values of status (for , NEW,ALLOTED,CANCELLED,COMPLETED),from Customer model (customer _id is given) via bookings array (also populated),

  • can deal with aggregate in mongoose?!

  • For that I first have to get all documents and then I have to iterate over all and then ,by (if-else ladder) I can push documents according to values. Or by doing four queries through aggregate. But actually I have large number of documents ,so I think it will not be efficient

  • Is there any other way to do this in javascript or in mongoose,mongodb(via queries). I am beginner .Please Help ,Thank You! (For nodejs)

    const bookingSchema = new Schema({
        category: {
            type: String,
           default: null
         },
         status: {
          type: String,
            enum: {
                values: ["NEW", "ALLOTED", "COMPLETED", "CANCELLED"],
                  message: "bad status"
                },
               default: "NEW",
               required: true
           }
         })
    
    
    
    
    
    const customerSchema= new Schema({
        email: {
            type: String,
           required:true
         },
    
       bookings: [
       {
        type: Schema.Types.ObjectId,
          ref: 'Booking'
        }
       ],
    })
    
about 4 years ago · Juan Pablo Isaza
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