Answer the question
In order to leave comments, you need to log in
Array search in mongo collection?
I have such a collection.
And I need to find matching values in it. Highlighted in red.
What the debugger shows below.
Mongoose: todos.find({ tags: { '$all': [ { _id: '5d68fe573970d024581165a7' } ] } }, { projection: {} })
[]
GET /my/todo/soso/5d68fe573970d024581165a7 304 14.975 ms - -
exports.myTODO = (req,res) =>{
TODO.find({ tags: { $all : {"_id":`${req.worker._id}`}} })
.exec((err, todos) =>{
if(err){
return res.status(400).json({
error: err
})
}
console.log(todos)
res.json(todos)
})
}
Answer the question
In order to leave comments, you need to log in
The problem was solved by reading the documentation. And the understanding that the $all method does not meet my functional needs.
$all Matches arrays that contain all the elements specified in the request.
$elemMatch Selects documents if the element in the array field matches all conditions specified in $elemMatch.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question