existId method
Checks if a document with the given ID exists in the collection.
This method validates the ID format and checks for document existence.
The idField should be a valid MongoDB ObjectId string representation.
Parameters:
idField- String representation of the MongoDB ObjectId Returnstrueif the document exists,falseif it doesn't exist or if the ID format is invalid. Example:
bool exists = await collection.existId('507f1f77bcf86cd799439011');
if (exists) {
print('Document found');
}
Implementation
Future<bool> existId(String idField) async {
var id = ObjectId.tryParse(idField);
return existOid(id);
}