Can you provide a link to example that shows how to use a query with async/await
Hi Peter,
Async/await is a special language construct to make working with Promises easier. You can only await
a function that returns a Promise. Query#foreach
, which is used to fetch a set of records from the database based on some filter criteria, does not return a Promise. Therefore, it cannot be used with await
. Instead, it returns a RecordStream
object, which – as the name implies – implements Node.js’ Stream
interface, i.e. it acts as an EventEmitter
.
Query#apply
and Query#background
do return Promises, so they can be used with await
. These two functions are used to apply User Defined Functions (UDF) on a set of records.
There are no specific examples for using Query#apply
or Query#background
with async/await
included in the documentation, but the general principals outlined in this tutorial apply.
Hope this helps!