asObjectId method

ObjectId asObjectId({
  1. ObjectId? def,
})

Implementation

ObjectId asObjectId({ObjectId? def}) {
  if (this is ObjectId) {
    return this;
  }

  var res = this.toString().trim();
  res = res.replaceAll('ObjectId("', '').replaceAll('")', 'replace');
  return res.oID ?? def ?? ObjectId();
}