Answer the question
In order to leave comments, you need to log in
How, when aggregating records in a project, to find _id in an array and get only it?
Is it possible to find _id when aggregating and leave only it in the array or output true (that it is present in the array)?
Here is the document
likes: [ObjectId('id_user_1'), ObjectId('id_user_2'), ObjectId('id_user_3')]
.aggregate([
$project: {
_id: 1,
likes: {
// вывести если найден _id - true, либо false , или оставить только найденный id в массиве или пустой массив
}
}
])
likes: { $filter: {
input: "$likes",
as: "likes",
cond: { "_id": request.sessionId }
}}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question