3

I am making a POST request to a CouchDB with a list of keys in the body.

This is a follow up on a previous question asked on Stack Overflow here: CouchDB Query View with Multiple Keys Formatting).

I see that the result has 711 rows returned in this case, with an offset of 209. To me an offset means valid results that have been truncated - and you would need to go to the next page to see them.

I'm getting confused because the offset, rows, and what I actually get does not seem to add up. These are the results that I'm getting:

{
  total_rows: 711,
  offset: 209,
  rows: [{
    id: 'b45d1be2-9173-4008-9240-41b01b66b5de',
    key: 2213,
    value: [Object]
  }, {
    id: 'a73d0b13-5d36-431f-8a7a-2f2b45cb480d',
    key: 2214,
    value: [Object]
  }, 
    etc BUT THERE ARE ONLY 303 OBJECTS IN THIS ARRAY????
  ]
}
Community
  • 1
  • 1
Zach Smith
  • 8,458
  • 13
  • 59
  • 133
  • Also, a similar-but-not the same question on how total rows/offset are related to the rows returned: http://stackoverflow.com/questions/33902858/couchdb-returns-wrong-total-rows/34805825?noredirect=1#comment57354084_34805825 – Zach Smith Jan 15 '16 at 07:25

2 Answers2

5

You have not supplied the query parameters you are using so I'll have to be a little general.

The total_rows value is the total number of rows in the view itself. The offset is the index in the view of the first matching row for the given query. The number of rows matching the query parameters are returned in the rows array, the total of which are trivial to obtain.

If there are no entries in the view for a direct key query, the offset value is the index into the view where the entry would be if it had the desired key.

Kerr
  • 2,792
  • 21
  • 31
0

It would seem that the offset refers to the number of documents BEFORE the first document that matches the key criteria is found.

and then the rows are all the documents that match the criteria.

i.e. rows returns all the documents that match the key criteria, and offset tells you what 'index' within all the docs returned by the view that the first document that matches the key criteria was found.

Please let me know if this is not correct :)

Zach Smith
  • 8,458
  • 13
  • 59
  • 133