deleteOid method
Deletes a document from the collection by its ObjectId.
This method performs the actual deletion using the MongoDB ObjectId directly. It retrieves the document before deletion to trigger the CollectionEvent.onDelete event with the deleted document data.
Parameters:
oid
- The MongoDB ObjectId of the document to delete
Returns true
if the deletion was successful, false
otherwise.
Example:
var objectId = ObjectId.fromHexString('507f1f77bcf86cd799439011');
bool deleted = await collection.deleteOid(objectId);
Implementation
Future<bool> deleteOid(ObjectId oid) async {
var oldData = await getByOid(oid);
var res = await collection.deleteOne(where.id(oid));
var result = res.success && res.nRemoved == 1;
if (result && oldData != null) {
await collectionEvent.onDelete.emit(oldData);
}
return result;
}