title: Querying on arrays in MongoDB C#
body: <p>I have a collection with following document type:</p>
  
  <pre><code>{
   field1: 1,
   field2: "test1",
   field3: [1,2,3]
  }
  </code></pre>
  
  <p>Suppose I have the following documents in my collection (ignoring <code>field1</code> and <code>field2</code> and only considering <code>field3</code>)</p>
  
  <p>Collection:</p>
  
  <pre><code>doc1-  {...
          field3: [3,4,5,6]
         }
  doc2-  {...
          field3: [3,4]
         }
  doc3-  {...
          field3: [1,2,3]
         }
  doc4-  {...
          field3: [3,6,7]
         }
  </code></pre>
  
  <p>Now, I am querying on this collection on <code>field3</code> with values <code>[3,4,6,7]</code>.</p>
  
  <p>So, I execute a query in the collection in such a way that I should get all documents that have all its array elements present in the query array.
  In my case, it should return the documents <code>doc2</code> and <code>doc4</code>, since all its elements of <code>field3</code> are existing in the query, but <code>Query.ALL</code> doesn't work.</p>
  
  <p>How can I accomplish this in MongoDB querying?</p>
  
  <p>(edited for more clarity)</p>
  
  <p>Why $all does'nt work?</p>
  
  <p>EX: If my questioning array is [3,4], when I use Query.All("field3",new BsonValue[]{3,4}),
  I will get all the documents with "field3" having all the elements in the questioning array i.e., 3 and 4. So In such case my result docs would be doc1 and doc2 from example above. But my requirement is only doc2. Because all the elements of my document should be there in my query array and not the other way.</p>
  
  <p>Why $in does'nt work?
  If atleast one element of the quetiong array is present in the document it is retrieved.
  Ex: questioning array is [3,4], when I use Query.In("field3",new BsonValue[]{3,4}),
  result will be all 4 documents of collection doc1, doc2, doc3 and doc4</p>