-
Schema for Event
const eventSchema = new mongoose.Schema( { title: { type: String, required: true }, schedule: { type: Date, required: true }, organizer: { type: mongoose.Schema.Types.ObjectId, ref: "user", required: true }, }, { timestamps: true } );
-
Schema for Bookings
const bookingSchema = new mongoose.Schema( { requester: { type: mongoose.Schema.Types.ObjectId, ref: "user", required: true }, event: { type: mongoose.Schema.Types.ObjectId, ref: "event", required: true }, }, { timestamps: true } );
I want to find all the bookings by organizer id.
I tried the below query but it didn’t work. Can anyone help me?
let bookings = await bookingModel.find({ "event.organizer": organizerId })
2
Answers
here is the solution How I solved this. Thank you all
There are basically 3 options here: