Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is no efficient and reliable way to query the for a date range you want given the date structure you have used. A regex style query would scan through the entire collection for example, and if you have millions of documents, that's not acceptable.</p> <p>You could theoretically create a MapReduce to better structure the data into a new collection. But, that will be more work to maintain (as MapReduces aren't automatically updated, and may make other queries and data fetching involve more steps than you'd like). </p> <p>Although, if you're willing to do that, I'd strongly suggest you instead just fix your data as I mentioned in my comment to be a standard YYYYMMDD. Even better, you may want to consider merging the time and would be to include the time stamp in the same field:</p> <pre><code>2013-07-21T14:30 </code></pre> <p>If you don't though, you can still do the single date query reasonably (although you'd want to index both the date and time as a compound index):</p> <pre><code>db.sales.ensureIndex({ sale_date: 1, sale_time: 1}) </code></pre> <p>Regarding the code, it's basically going to look like this:</p> <pre><code>BasicDBObject date = new BasicDBObject("sale_date", "21.07.2013"); BasicDBObject time = new BasicDBObject("sale_time", new BasicDBObject("$gte", "18:00"). append("$lte", "19:00")); BasicDBObject andQuery = new BasicDBObject(); List&lt;BasicDBObject&gt; obj = new ArrayList&lt;BasicDBObject&gt;(); obj.add(date); obj.add(time); andQuery.put("$and", obj); cursor = coll.find(andQuery); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload