Documentation Home
MySQL Shell 8.0
Related Documentation Download this Manual
PDF (US Ltr) - 376.8Kb
PDF (A4) - 371.1Kb
HTML Download (TGZ) - 74.7Kb
HTML Download (Zip) - 86.6Kb


MySQL Shell 8.0  /  ...  /  Conversions for representations of BSON data types

7.2.3 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