existId method

Future<bool> existId(
  1. String idField
)

Checks if a document with the given ID exists in the collection.

The idField should be a valid MongoDB ObjectId string.

Returns true if the document exists, otherwise false.

Implementation

Future<bool> existId(String idField) async {
  var id = ObjectId.tryParse(idField);
  if (id == null) return false;
  var count = await collection.count(where.id(id));
  return count > 0;
}