Return documents with desired values in MongoDB, filter, c#

Viewed 34

Example of a structure in the database:

{
    id: 0,
    Numbers: [5, 10, 11]
}
{
    id: 1,
    Numbers: [11, 512, 7, 28]
}

If I make a filter like this:

List<int> n = new List<int>() { 7, 11 };
var filter = builder.Eq("Numbers", n);

Mongodb does not return a single item - as it seems to understand the equivalence {7, 11} clearly the question is: how do I design a filter so that mongodb only returns the 2nd element - in other words: I need a clear filter condition - for example {7, 11}

1 Answers

You can to use the All method

List<int> n = new List<int>() { 7, 11 };
var filter = builder.All("Numbers", n);
Related