Hi!
I'm quite new to CouchDB and map/reduce and played a little around
with it. Currently, I am trying to find pairs of two documents which
fulfill a special condition. E.g., consider the following documents in
the store (_id and _rev are left out): [{price: 1},{price: 5},{price:
9},{price: 1000}]
Now I would like to find all pair of documents, where (doc1.price + 4
== doc2.price). How can I express this in couchdb? I expect the
following result: [[{price: 1},{price: 5}], [{price: 5},{price:9}]]
My first try was:
map: function(doc){
emit(null, doc);
}
reduce: function(key, values){
for(var i in values){
for(var j in values){
if(values[i].price + 4 == values[j]) return [values[i], values[j]];
}
}
}
But then I recognized the rereduce property in CouchDB and that the
values of the reduce funtion can be only intermediate results. So how
can I express what I want to do in map reduce?
Thx!