getById method

Future<Map<String, Object?>?> getById(
  1. String id
)

Retrieves a single document by its ID.

This method converts the string ID to an ObjectId and delegates to getByOid for the actual retrieval. The returned document is processed through form validation.

Parameters:

  • id - String representation of the document's ObjectId

Returns the document as a map if found, null if not found or if the ID format is invalid.

Example:

var user = await collection.getById('507f1f77bcf86cd799439011');
if (user != null) {
  print('User name: ${user['name']}');
}

Implementation

Future<Map<String, Object?>?> getById(String id) async {
  var oid = ObjectId.tryParse(id);
  return getByOid(oid);
}