I would like to 'find' the following item, based on its 'guess.body':
{
"guess": [
{
"body": "findme",
}
],
"_id": "608ee73b18a16e39e809203f"
}
This item is located in a collection called "ask", with the following model:
const askSchema = new Schema ({
guess: [{type:Schema.Types.ObjectId, ref:'guess'}],
})
In order to do this, I've tried 2 queries:
The first one:
const askByGuess = await ask.find().populate("guess").find({"guess.body":"findme"}) res.status(200).json(askByGuess)
which return an empty arrary
the second one (based on this answer: Find after populate mongoose)
const askByGuess = await ask.find().populate({path:"guess", match{body:"findme"}}).exec(function(err, ask) {ask = ask.filter(function(ask) {return ask.guess})}) res.status(200).json(askByGuess)
which returns "1".
Could someone indicate to me what I'm doing wrong?
Thank you!