findAndModify
findAndModify is an atomic single-document operation in MongoDB that combines querying, updating or removing a document in one step. It locates a document matching a query and either updates its fields, removes it, or inserts a new document if no match is found (upsert). The operation can also apply a sort to determine which document to act on when multiple candidates match.
Parameters typically include: query (the filter), sort (to choose among matches), update (the update operators to
Since it's a single-document, atomic operation, it avoids race conditions within that document, but it does not
Usage today: prefer findOneAndUpdate to increment counters, modify fields, or replace documents; use findOneAndDelete to remove