0

Collection.modify() is a "terminal" operation, so it doesn't return a Collection but a Promise of the number of modified objects.

But what if I want to have the modified objects? Something like

await db.foos
  .filter(somePredicate)
  .modifyAndReturnCollection(modification)
  .toArray();

The only workaround I see is something like

const modifiedFoos = [];
await db.foos
  .filter(somePredicate)
  .modify(foo => {
    ... //modify foo
    modifiedFoos.push(foos);
  })
  .then(() => modifiedFoos);

But it's not super clean and it would be nice if there is a version of modify() that returns a Collection so that you can call other Collection operations on it (each(), toArray(), etc).

Ricola
  • 2,621
  • 12
  • 22

0 Answers0