I'm testing CouchDB v2.3.1 and I'm having trouble understanding a particular result.
This is current db state filtered by a custom view:
curl 'http://127.0.0.1:5984/music/_design/albums/_view/_by_name' | json_pp
{
"offset" : 0,
"total_rows" : 3,
"rows" : [
{
"id" : "42dc72485892b5de28807f28130016c6",
"value" : {
"by" : "The Beatles",
"album" : {
"title" : "Abbey Road",
"year" : 1969
}
},
"key" : "Abbey Road"
},
{
"value" : {
"album" : {
"year" : 1965,
"title" : "Help!"
},
"by" : "The Beatles"
},
"key" : "Help!",
"id" : "42dc72485892b5de28807f28130016c6"
},
{
"id" : "42dc72485892b5de28807f28130016c6",
"value" : {
"by" : "The Beatles",
"album" : {
"title" : "Sgt. P",
"year" : 1967
}
},
"key" : "SGt. P"
}
]
}
As you can see, I have 3 rows(Beatle albums), who´s keys are album names.
Now the following query return an offset of 1. As you can see above, there is no row that has a key with name "Hel!". Notice that I'm filtering the query with the key="Hel!"
query param
curl 'http://127.0.0.1:5984/music/_design/albums/_view/_by_name?key="Hel!"' | json_pp
{
"offset" : 1,
"total_rows" : 3,
"rows" : []
}
Now the following query return an offset of 2. As you can see above, there is no row that has a key with name "No-such-namea!".
curl 'http://127.0.0.1:5984/music/_design/albums/_view/_by_name?key="No-such-namea"' | json_pp
{
"rows" : [],
"total_rows" : 3,
"offset" : 2
}
From this answer:
The offset is the index in the view of the first matching row for the given query
I understand that, if there is a match, the offset should be the index on the unfiltered view, of the first match from the rows returned.
Therefore, I'm not understanding why the offset is not 0 in the two previous examples.
Thank you for your time.