Note that there are some explanatory texts on larger screens.

plurals
  1. POCouchDB Modelling - Time filtered and group data
    primarykey
    data
    text
    <p>I'm trying to build up my understanding of the CouchDB and how to model data for some real world scenarios. I've done as many 'get me blog posts by date' as I can for now ;)</p> <p>Given documents like so:</p> <pre><code>{ "_id": "couch1", "_rev": "2-338d0a592ad1e5570000002b00000000", "eventType": "event1", "date": 1328805860000 } { "_id": "couch2", "_rev": "1-1e0315c2e1ca7f5f0000002b00000000", "eventType": "event1", "date": 1328133600000 } { "_id": "couch3", "_rev": "1-154cd416b78cb2ef0000002b00000000", "eventType": "event2", "date": 1325434920000 } </code></pre> <p><em>Where the date is an epoch would it be possible to ask Couch to make a view where you asked for all "events" that happened betweem two timestamps and then group that data by the "eventType"?</em></p> <p>So using the above and assuming the timestamps passed in encompass those documents - we'd want to see output:</p> <pre><code>"event1": 2 "event2": 1 </code></pre> <p><em>Further info I have obtained</em> </p> <p>I'm aware that Couch will sort by key so if I wanted a 'top 10' then that would be a second phase but I can handle that.</p> <p>So the core problem here is that you are filtering by one column but then grouping by another?</p> <p>If we use the following map function:</p> <pre><code>function (doc) { emit([doc.date, doc.eventType], doc.eventType); } </code></pre> <p>with a <code>count</code> reduce function we see that because the timestamps are essentially unique Couch cannot group and key has the value 1.</p> <p>So you can change the map function to the following:</p> <pre><code>function (doc) { emit([doc.eventType, doc.date], doc.eventType); } </code></pre> <p>And then change the <code>group level</code> to 1 which will group correctly by event but your data cannot then be sliced by time because your primary ordering is by the event name, meaning that time ordering is now broken?</p> <p>Do people have any war stories on this? Does this need to be done with re-reduce?</p> <p>Many thanks in advance to anyone taking time to read this</p> <p>Eggsy</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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