couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From svilen>
Subject what's the order of docs/keys going into reduce func?
Date Sat, 22 Sep 2012 10:05:19 GMT
say i have some lamp status monitoring records, i.e.

 { "seq": 1, "name": "a", },
 { "seq": 2, "name": "b", },
 { "seq": 2, "name": "a", "on": true},
 { "seq": 3, "name": "a", },
 { "seq": 7, "name": "a", "on": true},


where default state is off, and when on, there's extra bool attribute
for it. Records are sequenced (in time) by some .seq param. And there's
many other here-irrelevant attributes. 

say i want a view for all lamps that the currently off.

so, something like:

map_func: function( doc) {
  if (doc.type == 'lamp') emit( [, doc.seq], doc ); 

reduce_func: function( keys, values, rereduce) {
  var v = values[ values.length-1];
  if (v == null || v.on) return null;
  return v;

always used with group_level= 1

but i get the very first state instead of very last state...

and in the debug-log, i see that the keys passed to reduce are reversed!

so i have to use descending=True, and only then it works correctly.

the question is, is this expected, or is the default order defined
somewhere else, or what?


View raw message