MySQL Shell 8.0  /  ...  /  Conversions for Representations of BSON Data Types

11.2.4 Conversions for Representations of BSON Data Types

When you specify the convertBsonTypes: true (--convertBsonTypes) option to convert BSON data types that are represented by JSON extensions, by default, the BSON types are imported as follows:

Date (โ€œdateโ€)

Simple value containing the value of the field.

Timestamp (โ€œtimestampโ€)

MySQL timestamp created using the time_t value.

Decimal (โ€œdecimalโ€)

Simple value containing a string representation of the decimal value.

Integer (โ€œintโ€ or โ€œlongโ€)

Integer value.

Regular expression (โ€œregexโ€ plus options)

String containing the regular expression only, and ignoring the options. A warning is printed if options are present.

Binary data (โ€œbinDataโ€)

Base64 string.

ObjectID (โ€œobjectIdโ€)

Simple value containing the value of the field.

The following control options can be specified to adjust the mapping and conversion of these BSON types. convertBsonTypes: true (--convertBsonTypes) must be specified to use any of these control options:

ignoreDate: true (--ignoreDate)

Disable conversion of the BSON โ€œdateโ€ type. The data is imported as an embedded JSON document exactly as in the input file.

ignoreTimestamp: true (--ignoreTimestamp)

Disable conversion of the BSON โ€œtimestampโ€ type. The data is imported as an embedded JSON document exactly as in the input file.

decimalAsDouble: true (--decimalAsDouble)

Convert the value of the BSON โ€œdecimalโ€ type to the MySQL DOUBLE type, rather than a string.

ignoreRegex: true (--ignoreRegex)

Disable conversion of regular expressions (the BSON โ€œregexโ€ type). The data is imported as an embedded JSON document exactly as in the input file.

ignoreRegexOptions: false (--ignoreRegexOptions=false)

Include the options associated with a regular expression in the string, as well as the regular expression itself (in the format /<regular expression>/<options>). By default, the options are ignored (ignoreRegexOptions: true), but a warning is printed if any options were present. ignoreRegex must be set to the default of false to specify ignoreRegexOptions.

ignoreBinary: true (--ignoreBinary)

Disable conversion of the BSON โ€œbinDataโ€ type. The data is imported as an embedded JSON document exactly as in the input file.

The following example imports documents from the file /europe/regions.json to the column jsondata in a relational table named regions in the mydb database. BSON data types that are represented by JSON extensions are converted to MySQL representations, with the exception of regular expressions, which are imported as embedded JSON documents:

mysqlsh user@localhost/mydb --import /europe/regions.json regions jsondata --convertBsonTypes --ignoreRegex