Reduce on _id
Mon, 07/25/2011 - 06:54
Hi,
I am indexing all members of a posted document so the following example will add two rows to the index (fieldA, fieldB)
{
"_id:",
"_rev":,
"posted": {
"fieldA": valA,
"fieldB": valB,
}
}
When valA == valB, I want to index both of them.
Problem: When I search for valA/valB, I don't want the example document to be returned twice.
In this scenario, the _id is unique, but how can I use that to resolve the problem?
Tue, 12/27/2011 - 15:47
Buy klonopin online without a prescription Borneo Behave Buy Ambien withdraw scala Klonopin sextet cryosurgery
Hi,
you could only emit if the fields differ:
function(doc) { if(doc.fieldA && doc.fieldB) { if(doc.fieldA === doc.fieldB) { // emit once emit(doc.fieldA, null); } else { // emit twice emit(doc.fieldA, null); emit(doc.fieldB, null); } } }Alternatively, you could query your view with the
?limit=1option so you only ever get one row back.Cheers
Jan
--