delete method

Future<bool> delete(
  1. String id
)

Deletes a document from the collection by its ID.

This method validates the ID format and attempts to delete the corresponding document. Triggers CollectionEvent.onDelete if successful.

Parameters:

  • id - String representation of the MongoDB ObjectId to delete

Returns true if the deletion was successful, false if the ID is invalid or the document doesn't exist.

Example:

bool deleted = await collection.delete('507f1f77bcf86cd799439011');
if (deleted) {
  print('Document deleted successfully');
}

Implementation

Future<bool> delete(String id) async {
  var oid = ObjectId.tryParse(id);
  if (oid != null) {
    return deleteOid(oid);
  }

  return false;
}