BsonObject.bsonObjectFrom constructor

BsonObject.bsonObjectFrom(
  1. dynamic value
)

Implementation

factory BsonObject.bsonObjectFrom(var value) {
  if (value is BsonObject) {
    return value;
  } else if (value is Int64) {
    return BsonLong(value);
  } else if (value is Int32) {
    return BsonInt(value.toInt());
  } else if (value is int) {
    return value.bitLength > 31 ? BsonLong(Int64(value)) : BsonInt(value);
  } else if (value is double) {
    return BsonDouble(value);
  } else if (value is String) {
    return BsonString(value);
  } else if (value is ObjectId) {
    return BsonObjectId(value);
  } else if (value is Map) {
    return BsonMap(Map<String, dynamic>.from(value));
  } else if (value is List) {
    return BsonArray(value);
  } else if (value == null) {
    return BsonNull();
  } else if (value is DateTime) {
    return BsonDate(value);
  } else if (value == true || value == false) {
    return BsonBoolean(value);
  } else if (value is Decimal) {
    return BsonDecimal128(value);
  } else if (value is UuidValue) {
    return BsonUuid(value);
  } else if (value is Timestamp) {
    return BsonTimestamp(value);
  }
  throw Exception('Not implemented for $value');
}