dotConnect for MongoDB Documentation
On this page
    Data Type Mapping
    On this page

    The table below contains type mapping rules that are used to map BSON types to .NET types.

    BSON Type

    MongoDBType

    SQL Engine Column

    .NET Data Type

    DoubleDoubleDOUBLEDouble
    Double in a column declared SINGLE or FLOAT4 (CREATE TABLE, EnsureCreated)DoubleSINGLESingle
    StringStringVARCHARString
    32-bit integerIntegerINTInt32
    32-bit integer in a column declared TINYINT or SMALLINT (CREATE TABLE, EnsureCreated)IntegerTINYINT, SMALLINTByte, Int16
    64-bit integerLongINT64Int64
    Decimal128Decimal128DECIMAL128String by default; Decimal or Double by Decimal128 Mapping
    BooleanBooleanBOOLEANBoolean
    DateDateDATETIMEDateTime, Kind by DateTime Kind (Utc by default)
    ObjectIdOidOIDString (24 hexadecimal digits)
    Binary data, subtype 4 (or 3, by Guid Format)UuidUUIDGuid
    Other binary dataBinarypart columns .base64 and .subTypeString
    Date with offset, stored by DateTimeOffset FormatDateTimeOffsetDATETIMEOFFSETDateTimeOffset
    Embedded documentObjectA column for each nested field; one VARCHAR with JSON with Complex As String or Json FieldsString (JSON)
    ArrayArrayA column per element (tags.0); one VARCHAR with JSON with Complex As String or Json FieldsString (JSON)
    Regular expressionRegexPart columns .pattern and .optionsString
    JavaScriptCodePart column .$codeString
    JavaScript with scopeScopeCodePart columns .$code, .$scopeString
    TimestampTimeStampPart columns .t and .iString; parts Int32
    NullNullMNULLString (the value is DBNull)
    MinKey, MaxKeyMinKey, MaxKeyMINKEY, MAXKEYString

    Notes:

    Parameter Types

    .NET Data Type

    BSON Type Written

    Byte, SByte, Int16, UInt16, Int32, UInt3232-bit integer
    Int64, UInt6464-bit integer
    Single, DoubleDouble
    DecimalDecimal128
    BooleanBoolean
    DateTimeDate; a DateTime of Unspecified kind is taken as DateTime Kind
    DateTimeOffsetBy DateTimeOffset Format
    GuidBy Guid Format (binary subtype 4 by default)
    StringString; ObjectId when MongoDBType=Oid
    Byte[] with MongoDBType=BinaryBinary data, subtype 0
    MongoDBDocumentEmbedded document
    NullNull

    Arrays can't be passed as parameters. A Byte[] value requires MongoDBType=Binary to be set explicitly.