Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>First, I would switch the order of your emit: </p> <pre><code>emit([doc.tags[i], doc.created]); </code></pre> <p><em>(leave out <code>doc</code> as well, you can just add <code>include_docs=true</code> to get the entire document, and your view won't take up so much disk-space in the process)</em></p> <p>Now you can query for the all the stories tagged as <code>"Business"</code> by using the following querystring:</p> <pre><code>startkey=["Business"]&amp;endkey=["Business",{}] </code></pre> <p>You'll get all the documents with the tag business, and they'll be sorted by date.</p> <p>This takes advantage of <a href="http://wiki.apache.org/couchdb/View_collation" rel="nofollow">view collation</a>, which basically is the rules governing how indexes are sorted/queried. For complex keys like this, the sorting is done for each item of the array <em>separately</em>. (ie. the first key is sorted first, the second key is sorted second, etc) This is why the order matters, as you must always move from left to right when querying a view index.</p> <p>If you want the 6 most recent, your querystring will need to change:</p> <pre><code>descending=true&amp;limit=6&amp;endkey=["Business"]&amp;startkey=["Business",{}] </code></pre> <p><strong>NOTICE</strong> You need to swap the <code>startkey</code>/<code>endkey</code> values, due to how the <code>descending</code> parameter works. See the <a href="http://wiki.apache.org/couchdb/HTTP_view_API" rel="nofollow">View reference page on the wiki</a> for further explanation.</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