title: MongoDB query on multiple fields
body: <p>I am storing some numbers in mongodb. For e.g.</p>
  
  <ul>
  <li>num1:5</li>
  <li>num2:10</li>
  <li>num1:11</li>
  <li>num2:15</li>
  </ul>
  
  <p>I want to find documents where for e.g. if I pass '7' the query should check if 7 lies between num1 and num2 and must return me this document.</p>
  
  <p>I tried </p>
  
  <pre><code>BasicDBObject query = new BasicDBObject("num1", new BasicDBObject("gte", 7).append("num2",new BasicDBObject("lte", 7)));
  </code></pre>
  
  <p>and </p>
  
  <pre><code>List&lt;BasicDBObject&gt; obj = new ArrayList&lt;BasicDBObject&gt;();
          obj.add(new BasicDBObject("num1", new BasicDBObject("gte", 7)));
          obj.add(new BasicDBObject("num2", new BasicDBObject("lte", 7)));
          query.put("$and", obj);
  </code></pre>
  
  <p>Both are not returning me the any result. Could you please let me know correct query for my purpose?</p>