I’d like to know if there is a way to find a document that has an array that includes all and only the elements passed in the query’s array. I know i could use {members: [id1, id2]} or (with the $all operator) but what if i the elements order is not the same?
Basically if the document has {members: [1, 2]} i want to be able to find it passing [2, 1] to the query, but it shouldn’t return the document if the query’s array includes any other number. The arrays should be the same except for the order.
That seems a good approach but how would i combine the $all and $size operators? I think i need to use aggregations pipelines but I might be wrong as I tried and it didn’t work.
I believe too since $setIntersection seems to be only available in aggregation.
Shared what you tried. You might be closer to a solution than you think.
While I was looking for $setIntersection examples to share, I discover $setEquals which would be a more direct way to do that compared to $size of $setIntersection.
And while I was writing I thought a way you can do it with $all and $size.
$setIntersection and $setEquals are not what i’m looking for, since the first one just returns documents with arrays that have elements in common and the second one returns arrays that have the same elements in other fields.