I
I
IDONTSUDO2019-08-30 16:39:06
MongoDB
IDONTSUDO, 2019-08-30 16:39:06

Array search in mongo collection?

I have such a collection.
5d6924f646f52692577147.png
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 - -

My code
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)
    })
}

What is the problem why it is not searched?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
IDONTSUDO, 2019-08-30
@IDONTSUDO

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 question

Ask a Question

731 491 924 answers to any question