Data Aggregation Using CouchDB

I have a process that sends documents similar to the ones below to CouchDB:

{ "timestamp": [2010, 8, 4, 9, 25, 24], "type": "quote", "bid": 95.0, "offer": 96.5 } 

Many such documents are published throughout the day, each of which corresponds accordingly.

I want to create a CouchDB view that returns the last quote stored every day.

I read View SQL Jockeys cookbook on how to create complex views, but I have problems with how to combine the map and reduce functions to achieve the desired result. The card function is simple; this is a reduction function that I'm having problems with.

Any pointers gratefully received.

+4
source share
1 answer

Create a function map that returns all documents for a specific period of time using the same key. For example, return all documents at 5 p.m. using the 17 key.

Create a decrease function that emits only the most recent bet for that hour. Your submission will return 24 documents, and your client-side code will make the final merge.

There are many ways to achieve this. You can get one last bet by releasing one key from your cartographic function, and then decreasing it by searching for all bets, but I'm not sure how this will be done for extremely large sets, such as those that you encountered the trading system.

Update

http://wiki.apache.org/couchdb/View_Snippets#Computing_simple_summary_statistics_.28min.2Cmax.2Cmean.2Cstandard_deviation.29

+2
source

All Articles