Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I may not have your query requirements down exactly, as you didn't specify. However, if you need to find any documents that start or end in a particular range, then you can apply most of what is written below. If that isn't quite what you're after, I can be more helpful with a bit more direction. :)</p> <p>If you use CouchDB, you can create your indexes by splitting up the parts of your date into an array. (<code>[year, month, day, hour, minute, second, ...]</code>)</p> <p>Your map function would probably look similar to:</p> <pre><code>function (doc) { var date = new Date(doc.PeriodStart); emit([ date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes() ] , null]); } </code></pre> <p>To perform any sort of range query, you'd need to convert your start and end times into this same array structure. From there, your view query would have params called <code>startkey</code> and <code>endkey</code>. They would would receive the array parameters for start and end respectively.</p> <p>So, to find the documents that started in the past 24 hours, you would send a querystring like this in addition to the full URI for the view itself: </p> <pre><code>// start: Apr 17, 2011 12:30pm ("24 hours ago") // end: Apr 18, 2011 12:30pm ("today") startkey=[2011,04,17,12,30]&amp;endkey=[2011,04,18,12,30] </code></pre> <p>Or if you want everything from this current year:</p> <pre><code>startkey=[2011]&amp;endkey=[2011,{}] </code></pre> <p>Note the <code>{}</code>. When used as an endkey: <code>[2011,{}]</code> is identical to <code>[2012]</code> when the view is collated. (either format will work)</p> <p>The extra components of the array will simply be ignored, but the further specificity you add to your arrays, the more specific your range can be. Adding reduce functions can be really powerful here, if you add in the <code>group_level</code> parameter, but that's beyond the scope of your question.</p>
 

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