I am trying to find whether all elements of the array are found inside an array in a MongoDB database using mongoose.
If my data in MongoDB is -
{
row: "A",
reserve: [1,2,3]
}
and if my query data is -
{
row: "A",
arr: [1,2] // I want it to return result
}
and if my query data is
{
row: "A",
arr: [1,2,4] // I want it to return null
}
I want to update the data but it is updating every time
Reserved.updateOne({row: "A", reserve: {$in: arr}, {
$push: {
reserve: arr
}
}, (err, result) => {
// ...
});
Please help me.
db.collection.aggregate([ { $project: { reserve: { $filter: { input: "$reserve", cond: { $in: [ "$$this", [ 1, 2 ] ] } } } } } ])findOnebecause I am usingupdateOnefor updating data.db.collection.updateOne({ row: "A", reserve: { $all: arr } })