Access to curent fields value during update

Hi All,
In some database engines such as Oracle, we can get access to current fields to value even the previous or next one using lead and lag.
Is it possible to get access to the current value of a document before the update? I know I can query it but it has some performance costs.

It might be possible within a Transaction. Might be worth looking into that.
Or consider ways to mitigate those performance costs, and query it.

Hi @Taha_43510,

I think what you are looking for is findAndModify() function.

It does two operations in one go. First it finds the document that matches the query and then updates it.

Yes, this function modifies and returns a single document. By default, the returned document does not include the modifications made on the update. To return the document with the modifications made on the update, use the new option.

Hope it helps!

If you still have any query, please feel free to get back to us.

Happy Learning :slight_smile:

Shubham Ranjan
Curriculum Support Engineer

1 Like

There’s one important caveat to keep in mind here:

… only one document is modified.

With the advent of 4.2 and multi-document atomicity, is there any way of doing this with bulk/multi-document updates? Perhaps through a cursor or transactions?