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 ConceptsThe following table presents the various SQL terminology and concepts and the corresponding MongoDB terminology and concepts.
SQL Terms/Concepts MongoDB Terms/Concepts document or BSON document table joins $lookup , embedded documentsSpecify 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) SELECT INTO NEW_TABLE MERGE INTO TABLE transactionsFor many scenarios, the denormalized data model (embedded documents and arrays) will continue to be optimal for your data and use cases instead of multi-document transactions. That is, for many scenarios, modeling your data appropriately will minimize the need for multi-document transactions.
ExecutablesThe following table presents some database executables and the corresponding MongoDB executables. This table is not meant to be exhaustive.
Database Server DB2 Server Database Client DB2 Client ExamplesThe following table presents the various SQL statements and the corresponding MongoDB statements. The examples in the table assume the following conditions:
_id: ObjectId("509a8fb2f3f4948bd2f983a0") , user_id: "abc123", age: 55, status: 'A' >
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 StatementsCREATE TABLE people ( id MEDIUMINT NOT NULL AUTO_INCREMENT, user_id Varchar(30), age Number, status char(1), PRIMARY KEY (id) )
Implicitly created on first insertOne() or insertMany() operation. The primary key _id is automatically added if _id field is not specified.
db.people.insertOne( user_id: "abc123", age: 55, status: "A" > )
However, you can also explicitly create a collection:
db.createCollection("people")
ALTER TABLE people ADD join_date DATETIME
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, updateMany() operations can add fields to existing documents using the $set operator.
db.people.updateMany( < >, < $set: < join_date: new Date( ) > > )
ALTER TABLE people DROP COLUMN join_date
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, updateMany() operations can remove fields from documents using the $unset operator.
db.people.updateMany( < >, < $unset: < "join_date": "" > > )