Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

76
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!