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

77
Vistas
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 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