updateField method

Future<void> updateField(
  1. String id,
  2. String field,
  3. Object? value
)

Updates a specific field of a document by its ID.

The id should be a valid MongoDB ObjectId string. The field specifies the field to be updated, and value is the new value to be assigned.

Implementation

Future<void> updateField(String id, String field, Object? value) async {
  var oid = ObjectId.tryParse(id);
  if (oid != null && await existId(id)) {
    await collection.updateOne(where.id(oid), modify.set(field, value));
  }
}