user8919059
user8919059

Reputation:

Mongoose - how to use Schema parameters?

So I have a parameter

venue: {
    type: mongoose.Schema.Types.ObjectId, ref: 'venue'
}

and I want to extract the id that is passed into the schema in a findById function like :

Event. 
     Venue.findById(id, callback).
     populate('venue').
     exec(function (err,event) {
          if (err) return handleError(err);
});

I know this isn't correct code - how should I fix it?

Upvotes: 0

Views: 36

Answers (1)

Orelsanpls
Orelsanpls

Reputation: 23515

Are you trying to get the value of the Event plus the value of the Venue behind the venue.id in Event?

Event.findOne({
  venue: id,
})
   .populate('venue')
   .exec()
   .then((ret) => {
     // ...
   })
   .catch((err) => {
     // ...
   });

Upvotes: 1

Related Questions