In SQL mode, dotConnect for MongoDB represents MongoDB collections as tables and document fields as columns. This topic describes how collections and documents are mapped to tables and columns.
[otherdb].collection syntax.[orders.archive].sqlite_master table and PRAGMA statements return information only about the tables that have already been used in queries.dotConnect for MongoDB determines the columns of a table and their types by analyzing the first documents of the collection. The number of documents to analyze is set by the Describe Amount connection string parameter (100 by default).
If a field has values of different types in the analyzed documents, the column type is determined in the following way:
A table can have up to 2000 columns.
Fields of embedded documents and array elements are represented as columns with dotted names, for example, address.city or tags.0.
In SQL statements, enclose such column names in double quotes or square brackets, for example, "address.city" or [address.city]. Otherwise, the statement fails with the "no such column: address.city" error.
The following table lists the special BSON types that are split into several columns.
| BSON type | Columns |
|---|---|
| Regular expression | re.pattern, re.options |
| Binary data | bin.base64, bin.subType |
| Timestamp | ts.t, ts.i |
| JavaScript code | code.$code |
In this table, re, bin, ts, and code are field names.
You can represent embedded documents and arrays as JSON columns instead of dotted columns:
Json Fields=customers.address;customers.tags. A listed field is represented as a column even if no document contains it.When you write data to such a column, a text value that starts with { or [ is parsed as Extended JSON.
The fields of such a JSON document are also available as hidden columns. Hidden columns aren't returned by SELECT *, but you can use them in queries. For example, with Json Fields=customers.address, the following query returns the address column as {"city":"London","street":"Baker St"}:
To get a value from a JSON column, use the MONGO_JSON_VALUE(json, path) SQL function. For example, the following expression returns Paris for a document with "city": "Paris" in the address field: