couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Søren Hilmer>
Subject Question on view design for both Hierarchy and Date.
Date Tue, 21 Sep 2010 06:53:07 GMT
Hi all

I have documents which has a place in both a hierarchy and on a time line.

So I wish to be able to query a view to get all documents (actually their
value), under a node in the hierarchy and between two dates.

A document could look like this:
   "path": [ "A", "B", "c6", "b9"],
   "time": "2010-09-20T23:00:00.000Z",
   "value": 117

I have come up with this map function, which emits every sub-path from the
root together with the date for each document:
function(doc) {
    if (doc.value) {
       var d = new Date(Date.parse(doc.time));
       var r = [];
       var p = [];

       for (var i in doc.path) {
           emit(p.concat(r), doc.value);

//reduce just sums the values

This allows me to do the wanted query
like, startkey=["A","B","c6",2010,9,20,12,0,0]&endkey=["A","B","c6",2010,9,20,22,0,0,{}]

Is there a better (for some value of better like: faster and/or uses less
space) approach to this problem?

The documents are actually only on the leaves in the hierarchy, but I need
to sum their values up the tree, can this extra information somehow be used
to improve the view?

I can get up to 500.000 of these documents pr. hour. would that be a problem
as I do several emits pr document?

Any tips are welcome.



Søren Hilmer, M.Sc., M.Crypt.

wideTrail                   Phone:  +45 25481225

Pilevænget 41           Email:  sh at <>

DK-8961  Allingåbro   Web:

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message