updateFields method

Future<void> updateFields(
  1. String id,
  2. Map<String, dynamic> fields
)

Updates multiple fields of a document by its ID.

The id should be a valid MongoDB ObjectId string. The fields map contains the fields to be updated and their new values.

Implementation

Future<void> updateFields(String id, Map<String, dynamic> fields) async {
  var oid = ObjectId.tryParse(id);
  if (oid != null) {
    var row = await collection.findOne(where.id(oid));
    if (row != null) {
      row.addAll(fields);
      await collection.modernUpdate(where.id(oid), row);
    }
  }
}