Ah, I had not considered multiple emits per doc. Thanks very much!
Jason Gordon | Principal | A S S U R E B R I D G E Office: +1 888 409 6995 | Mobile: +1 978 885 6102 | Fax: +1 888 409 6995 Email: [email protected] On Fri, Apr 7, 2017 at 3:33 PM, Jan Lehnardt <[email protected]> wrote: > > > On 7 Apr 2017, at 19:15, Jason Gordon <[email protected]> > wrote: > > > > Hi Jan, > > > > You raise a good point. But it leads to another, similar question > > > > If rows 50 and 51 both contain a user with lastname Jackson, the recipe > > says to use the following as the next key > > > > startkey=[02134,Jackson] endKey=[02134,{}] limit=51 startkey_doc_id=234 > > (assuming _id for Jackson 234) > > > > but why not > > > > startkey=[02134] endKey=[02134,{}] startkey_doc_id=234 limit=51 > > because that produces a different result. views are sorted by key first, > and only if keys are identical, those rows are sorted by doc_id. > > A document can occur in a view result multiple times, so you are not > guaranteed to match the next page if you leave out the specific key that > lead you to row 51. > > In your example with zip+lastname that’s less likely, but imagine docs > with a list of tags: [‘red’, ‘green’, ‘blue’], now the same doc (id 234) > shows up multiple times and in different parts of the overall view result. > When you now do tag-by-zipcode, and your query, while paginating green, you > would jump into row 51 or blue. > > Does that help? :) > > Best > Jan > -- > > > > > > > Would they not accomplish the same thing? Is the 2nd query inefficient? > > > > Thanks, > > > > Jason > > > > > > > > > > > > > > Jason Gordon | Principal | A S S U R E B R I D G E > > Office: +1 888 409 6995 | Mobile: +1 978 885 6102 | Fax: +1 888 409 > > 6995 > > Email: [email protected] > > > > On Fri, Apr 7, 2017 at 5:32 AM, Jan Lehnardt <[email protected]> wrote: > > > >> > >>> On 6 Apr 2017, at 21:18, Jason Gordon <[email protected]> > >> wrote: > >>> > >>> The CouchDB docs 6.2.5 pagination recipe recommends to use the > >>> "startkey_docid for pagination if, and only if, the extra row you fetch > >> to > >>> find the next page has the same key as the current startkey" > >>> > >>> Why can't you keep the start key the same and just keep updating the > >>> startkey_docid? > >>> > >>> For example: > >>> > >>> if a view emits a key of [doc.zipcode, doc.lastname] > >>> > >>> And I'm looking for all people in a given zipcode. > >>> and I do an initial query with startkey=[02134] endKey=[02134,{}] > >> limit=51 > >>> > >>> the 50th user has a last name of Jackson (_id 123) and the 51st user > >> has a > >>> lastname of Johnson (_id 234). > >>> > >>> I could ask for the next page in two ways: > >>> > >>> *startkey=[02134,Johnson] endKey=[02134,{}] limit=51* > >>> > >>> OR > >>> > >>> *startkey=[02134] endKey=[02134,{}] startkey_doc_id=234 limit=51* > >>> > >>> Is there something wrong with the second approach? Would it perform > >> poorly? > >> > >> What if lastname in row 51 is also Jackson? :) > >> > >> Best > >> Jan > >> -- > >> > >>> > >>> Thanks > >>> > >>> Jason > >>> > >>> > >>> Jason Gordon | Principal | A S S U R E B R I D G E > >>> Office: +1 888 409 6995 | Mobile: +1 978 885 6102 | Fax: +1 888 > 409 > >>> 6995 > >>> Email: [email protected] > >> > >> -- > >> Professional Support for Apache CouchDB: > >> https://neighbourhood.ie/couchdb-support/ > >> > >> > > -- > Professional Support for Apache CouchDB: > https://neighbourhood.ie/couchdb-support/ > >
