getByOid method

Future<Map<String, Object?>?> getByOid(
  1. ObjectId? oid
)

Retrieves a single document by its ObjectId.

This method performs the actual document retrieval using the MongoDB ObjectId directly. The returned document is processed through the form validation system to ensure proper data formatting.

Parameters:

  • oid - The MongoDB ObjectId of the document to retrieve

Returns the document as a map if found, null if not found or if the ObjectId is null.

Example:

var objectId = ObjectId.fromHexString('507f1f77bcf86cd799439011');
var document = await collection.getByOid(objectId);

Implementation

Future<Map<String, Object?>?> getByOid(ObjectId? oid) async {
  if (oid == null || !await existOid(oid)) {
    return null;
  }

  var res = await collection.findOne(where.id(oid));
  if (res != null) {
    return await toModel(res);
  }
  return null;
}