Realm function housekeeping

I’m writing a cloud function that makes a query and does some housekeeping:

const testFn1 = async (args) => {
  try {
    const results = await query(args);
    update(results).then(() => console.log('update stats finished'))
    return results;
  } catch (e) {
    console.error(e)
  }
}

I have to run the query and return the result fast but also do some updates (statistics) based on this result. Updates are not crucial and can also be carried at a later time.

So the question is could this be done any better or is it ok to leave it like this?

Hi @Roby_Rodriguez,

This seems fine as you utilize promise async ability.

However, you may consider bulk updates if you want a large number of updated docs in one go:

https://docs.mongodb.com/realm/mongodb/crud-and-aggregation-apis/#ordered-bulk-write-operation-availability

Thanks
Pavel