I have a channel schema like this:
const channelSchema = new mongoose.Schema(
{
name: {
type: String,
unique: true
}
}
);
And this is the feedback schema:
const feedbackSchema = new mongoose.Schema({
channelId: {
type: mongoose.Schema.Types.ObjectId,
ref: "channel",
require: true
}
});
How can I find the feedback by channel name?
Feedback.find({channelId.name : 'something'})
Thanks
You cant query for a property on an object that doest exists, I would suggest first querying for the channel, grabbing the id and doing the lookup from there.
const channel = await Channel.findOne({ name });
const feedback = await Feedback.find({ channelId: channel._id })
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With