Node since version 8 allows you to do this:

const allDocs = await larch.list()

for (const id of allDocs) {
  const doc = await larch.get(id)
}

Which gets you what you’d expect, but again, don’t use that in this case here :)


> On 13. Feb 2019, at 20:37, Stephan Mühlstrasser 
> <[email protected]> wrote:
> 
> Hi Jan,
> 
> Am 13.02.2019 um 10:28 schrieb Jan Lehnardt:
>> Hi Stephan,
>> 
>> welcome to CouchDB and asynchronous programming :)
>> 
>> Let’s annotate your code to see what’s happening:
>> 
>> ...
> 
> thank you for the detailed explanation! I understand now how the problem
> is caused.
> 
>> There are multiple ways to solve this in asynchronous programming. One would 
>> be a queue with a maximum parallel jobs setting that keeps concurrent 
>> operations to a nice minimum, but eventually gets you all the results. I’ve 
>> used https://www.npmjs.com/package/promise-queue in the past for this.
> 
> I will save that recommendation for a later stage in my journey to learn
> asynchronous JavaScript programming... It is really surprising to me
> that one is "condemned" to the asynchronous model in plain JavaScript
> and that an extra package is needed to avoid the asynchronous mode if
> desired.
> 
>> To get the same result in CouchDB, you can pass in the `include_docs` 
>> parameter set to `true`, then CouchDB will fetch the doc bodies for you in 
>> the original `larch.list()` request and include the doc bodies inside the 
>> result set.
> 
> Using "larch.list({include_docs: true})" indeed does the trick, and the
> program works as expected.
> 
> Thank you, Jan!
> Stephan

Reply via email to