title: Using QueryBuilder to find an array that contains an element
body: <p>I have a database structure like this:</p>
  
  <pre><code>{
      "_id" : "Foo",
      "registrations" : [ 
          101, 
          102
      ]
  }
  </code></pre>
  
  <p>What I would like to do is create a query that will find all documents that contain a "registrations" array with the value <code>101</code> contained within it. I would like to use the <a href="http://api.mongodb.org/java/3.0/com/mongodb/QueryBuilder.html" rel="nofollow noreferrer">QueryBuilder</a> if at all possible because I typically find it easier to use.</p>
  
  <p>Based on <a href="https://stackoverflow.com/a/16815355/531762">this answer</a>, I tried to use <code>elemMatch()</code> to find it, but that didn't seem to have the desired effect:</p>
  
  <pre><code>QueryBuilder.start().put("registrations").elemMatch(new BasicDBObject("_id", 101)).get();
  </code></pre>
  
  <p>However, the stacktrace said that it is trying to cast the <code>BasicDBObject</code> to an <code>Integer</code> and failing.</p>
  
  <pre><code>java.lang.ClassCastException: java.lang.Integer cannot be cast to com.mongodb.DBObject
  </code></pre>
  
  <p>So how can I create a query using QueryBuilder that will find all documents that contain a "registrations" array witht he value <code>101</code> contained within it?</p>