findAndModify method

Future<Map<String, dynamic>?> findAndModify({
  1. dynamic query,
  2. dynamic sort,
  3. bool? remove,
  4. dynamic update,
  5. bool? returnNew,
  6. dynamic fields,
  7. bool? upsert,
})

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 returnNew option.

Implementation

Future<Map<String, dynamic>?> findAndModify(
    {query,
    sort,
    bool? remove,
    update,
    bool? returnNew,
    fields,
    bool? upsert}) async {
  if (db._masterConnectionVerified.serverCapabilities.supportsOpMsg) {
    var result = await modernFindAndModify(
        query: query,
        sort: sort,
        remove: remove,
        update: update,
        returnNew: returnNew,
        fields: fields,
        upsert: upsert);
    return result.value;
  }

  return legacyFindAndModify(
      query: query,
      sort: sort,
      remove: remove,
      update: update,
      returnNew: returnNew,
      fields: fields,
      upsert: upsert);
}