MongoDB to SQL Mapping
On this page
Here are a few conceptual mappings between MongoDB and SQL.
Databases
Similar to MongoDB, SingleStoreDB databases serve as a lightweight container for scoping permissions and organizing collections, and they are implicitly created with a default configuration when collections are created.
Collections to Tables
In MongoDB, collections are containers for documents.createCollection
command or implicitly when a write occurs targeting a collection.
Documents to Rows
Whenever a BSON document is inserted through SingleStore Kai ("the API"), the document itself is mapped to a row in a target table._
column.
When a document is retrieved through the API, values from all the columns except the _
column are added to the document first._
column are included afterwards._
column has the same name as another column, the value from the existing column takes precedence over the field in the _
column.
Value Conversions
Values passed to and from BSON documents to columns in a SingleStoreDB table undergo a conversion process.
BSON to JSON
The API does not support the BSON data type for storage.int64
type may be interpreted as an int32
type with the same value.
MongoDB Terminologies and Concepts Mappings Table
The following table maps MongoDB terminologies and concepts to their SQL equivalents:
MongoDB Terms/Concepts |
SQL Terms/Concepts |
---|---|
Database |
Database |
Collection |
Table |
View |
View |
Document |
Row |
Top-level field |
Column |
Additional fields not matching a column |
|
Index |
Index |
Primary key: the |
Primary key: Any unique column (including the |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CREATE TABLE
and ALTER TABLE
Statement Examples
The following table shows CREATE TABLE
and ALTER TABLE
statements written in SQL and their MongoDB equivalents:
MongoDB Statements |
SQL Statements |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
SELECT
Statement Examples
The following table shows SELECT
statements written in SQL and their MongoDB equivalents:
MongoDB Statements |
SQL Statements |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
INSERT
Statement Examples
The following table shows INSERT
statements written in SQL and their MongoDB equivalents:
MongoDB Statements |
SQL Statements |
---|---|
|
|
|
|
UPDATE
Statement Example
The following table shows UPDATE
statements written in SQL and their MongoDB equivalents:
MongoDB Statements |
SQL Statements |
---|---|
|
|
DELETE
Statement Examples
The following table shows DELETE
statements written in SQL and their MongoDB equivalents:
MongoDB Statements |
SQL Statements |
---|---|
|
|
|
|
Aggregate Function Examples
The following table shows aggregate functions written in MongoDB and their SQL equivalents:
MongoDB Statements |
SQL Statements |
---|---|
|
|
|
|
Last modified: June 28, 2023