couchdb-python icon indicating copy to clipboard operation
couchdb-python copied to clipboard

iterview does not work for views on which you specify reduce in the options.

Open mountainpaul opened this issue 10 years ago • 4 comments

So since your doing a reduce there is no "id" value, and it will throw an exception. It would be nice to fix this, but I think you would have to do a skip.

mountainpaul avatar Jan 01 '16 07:01 mountainpaul

Hmm, it feels like it might work with startkey, but without startkey_docid. Perhaps you can give that a whirl? The iterview() code could only pass startkey_docid if reduce is not specified, or even when id is not available on the resutl.

djc avatar Jan 04 '16 09:01 djc

Specifying a startkey does not appear to help. It appears for the first batch that 'id' is available, but on the second batch (i.e. next iteration) the id is not available.

mountainpaul avatar Mar 18 '16 15:03 mountainpaul

Changing client.py at line 870 from

           options.update(startkey=rows[-1]['key'], startkey_docid=rows[-1]['id'])
to 
           try:
                options.update(startkey=rows[-1]['key'], startkey_docid=rows[-1]['id'])
           except KeyError: 
                if rows[-1]['key']!=rows[-2]['key']:
                      options.update(startkey=rows[-1]['key'])
                else:
                      raise

fixed my issue, but in my specific case the key was unique because of the group level.

mountainpaul avatar Mar 18 '16 15:03 mountainpaul

When doing a reduce, isn't each key unique, even for different group levels? Seems like it should be feasible to just omit the startkey_docid when reduce is True. I'm trying this out now.

nedgar avatar Oct 13 '16 02:10 nedgar