Sam
Sam

Reputation: 4484

reduce output must shrink more rapidly, on adding new document

I have couple of documents in couchdb, each having a cId field, such as -

{
   "_id": "ccf8a36e55913b7cf5b015d6c50009f7",
   "_rev": "8-586130996ad60ccef54775c51599e73f",
   "cId": 1,
   "Status": true
}

I have a simple view, which tries to return max of cId with map and reduce functions as follows -

Map

function(doc) {
   emit(null, doc.cId);
}

Reduce

function(key, values, rereduce){

 return Math.max.apply(null, values);
}

This works fine (output is 1) until I add one more document with cId = 2 in db. I am expecting output as 2 but it starts giving error as "Reduce output must shrink more rapidly". When I delete this document things are back to normal again. What can be the issue here? Is there any alternative way to achieve this?

Note: There are more views in db, which perform different role and few return json as well. They also start failing on this change.

Upvotes: 0

Views: 309

Answers (1)

pwagner
pwagner

Reputation: 1244

You could simply use the built-in _statsreduce function, in order to get the maximum value. It is returned in the "max" field.

Upvotes: 1

Related Questions