- Reference >
- SQL to MongoDB Mapping Chart
SQL to MongoDB Mapping Chart¶
On this page
In addition to the charts that follow, you might want to consider the Frequently Asked Questions section for a selection of common questions about MongoDB.
Terminology and Concepts¶
The following table presents the various SQL terminology and concepts and the corresponding MongoDB terminology and concepts.
SQL Terms/Concepts | MongoDB Terms/Concepts |
---|---|
database | database |
table | collection |
row | document or BSON document |
column | field |
index | index |
table joins | embedded documents and linking |
primary key Specify any unique column or column combination as primary key. |
In MongoDB, the primary key is automatically set to the _id field. |
aggregation (e.g. group by) | aggregation framework |
Executables¶
The following table presents the MySQL/Oracle executables and the corresponding MongoDB executables.
MongoDB | MySQL | Oracle | Informix | DB2 | |
---|---|---|---|---|---|
Database Server | mongod |
mysqld |
oracle |
IDS |
DB2 Server |
Database Client | mongo |
mysql |
sqlplus |
DB-Access |
DB2 Client |
Examples¶
The following table presents the various SQL statements and the corresponding MongoDB statements. The examples in the table assume the following conditions:
The SQL examples assume a table named
users
.The MongoDB examples assume a collection named
users
that contain documents of the following prototype:
Create and Alter¶
The following table presents the various SQL statements related to table-level actions and the corresponding MongoDB statements.
SQL Schema Statements | MongoDB Schema Statements | Reference |
---|---|---|
Implicitly created on first However, you can also explicitly create a collection: |
See
insert() and
createCollection()
for more information. |
|
Collections do not describe or enforce the structure of its documents; i.e. there is no structural alteration at the collection level. However, at the document level, |
See the Data Modeling Considerations for MongoDB Applications, update() , and $set for more
information on changing the structure of documents in a
collection. |
|
Collections do not describe or enforce the structure of its documents; i.e. there is no structural alteration at the collection level. However, at the document level, |
See Data Modeling Considerations for MongoDB Applications, update() , and $unset for more
information on changing the structure of documents in a
collection. |
|
See ensureIndex()
and indexes for more information. |
||
See ensureIndex()
and indexes for more information. |
||
See drop() for
more information. |
Insert¶
The following table presents the various SQL statements related to inserting records into tables and the corresponding MongoDB statements.
SQL INSERT Statements | MongoDB insert() Statements | Reference |
---|---|---|
See insert()
for more information. |
Select¶
The following table presents the various SQL statements related to reading records from tables and the corresponding MongoDB statements.
Note
The find()
method always includes the _id
field in the returned documents unless specifically excluded through
projection. Some of the SQL queries below may include an
_id
field to reflect this, even if the field is not included in the
corresponding find()
query.
SQL SELECT Statements | MongoDB find() Statements | Reference |
---|---|---|
See find()
for more information. |
||
See find()
for more information. |
||
See find()
for more information. |
||
See find()
for more information. |
||
See find()
for more information. |
||
See find()
and $ne for more information. |
||
See find()
and $and for more information. |
||
See find()
and $or for more information. |
||
See find()
and $gt for more information. |
||
See find()
and $lt for more information. |
||
See find() ,
$gt , and $lte for
more information. |
||
See find()
and $regex for more information. |
||
See find()
and $regex for more information. |
||
See find()
and sort()
for more information. |
||
See find()
and sort()
for more information. |
||
or |
See find()
and count() for
more information. |
|
or |
See find() ,
count() , and
$exists for more information. |
|
or |
See find() ,
count() , and
$gt for more information. |
|
See find()
and distinct()
for more information. |
||
or |
See find() ,
findOne() ,
and limit()
for more information. |
|
See find() ,
limit() , and
skip() for
more information. |
||
See find()
and explain()
for more information. |
Update Records¶
The following table presents the various SQL statements related to updating existing records in tables and the corresponding MongoDB statements.
SQL Update Statements | MongoDB update() Statements | Reference |
---|---|---|
See update() ,
$gt , and $set for more
information. |
||
See update() ,
$inc , and $set for more
information. |