I need to compare two nested arrays with mongo but I'm not really an expert so I need some help on doing that.
Let's say I have a document with an array slots:
[
[
{
"start": 1,
"end": 2
}
],
[
{
"start": 3,
"end": 4
},
{
"start": 5,
"end": 6
}
]
]
And I need to know if another array is a subset of it:
db.collection.aggregate([
{
$project: {
slots: {
$setIsSubset: [
[
[
{
start: 1,
end: 2
}
],
[
{
start: 3,
end: 4
},
{
start: 5,
end: 6
}
]
],
"$slots"
]
}
}
}
])
This returns true, but if I remove one element in the second sub array, it returns false as the sub array isn't equal anymore.
I thought of doing some kind of $map where I would compare each sub array but I realized I didn't know how to reference the index of the array we're comparing to.
Any ideas? Thanks
Edit : the first level of the stored array and the array we're comparing it with are days of the week so that information needs to be kept.