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.除了下面的图表外,您可能还想考虑常见问题部分,了解有关MongoDB的一些常见问题。
Terminology and Concepts术语和概念
The following table presents the various SQL terminology and concepts and the corresponding MongoDB terminology and concepts.下表介绍了各种SQL术语和概念以及相应的MongoDB术语和概念。
| SQL | MongoDB |
|---|---|
$lookup | |
|
|
| |
SELECT INTO NEW_TABLE |
|
MERGE INTO TABLE |
|
UNION ALL | $unionWith |
|
|
Executables可执行文件
The following table presents some database executables and the corresponding MongoDB executables. This table is not meant to be exhaustive.下表显示了一些数据库可执行文件和相应的MongoDB可执行文件。此表并非详尽无遗。
| MongoDB | MySQL | Oracle | Informix | DB2 | |
|---|---|---|---|---|---|
mongod | mysqld | oracle | IDS | DB2 Server | |
mongosh | 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:下表显示了各种SQL语句和相应的MongoDB语句。表中的示例假设了以下条件:
The SQL examples assume a table namedSQL示例假定一个名为people.people的表。The MongoDB examples assume a collection namedMongoDB示例假设一个名为peoplethat contain documents of the following prototype:people的集合包含以下原型的文档:{
_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语句和相应的MongoDB语句。
|
|
|
|
|
|
|
|
|
|
|
|
For more information on the methods and operators used, see:有关所用方法和运算符的更多信息,请参阅:
Insert插入
The following table presents the various SQL statements related to inserting records into tables and the corresponding MongoDB statements.下表显示了与将记录插入表中相关的各种SQL语句和相应的MongoDB语句。
SQL INSERT | MongoDB insertOne() |
|---|---|
|
|
For more information, see 有关更多信息,请参阅db.collection.insertOne().db.collection.insertOne()。
Select
The following table presents the various SQL statements related to reading records from tables and the corresponding MongoDB statements.下表显示了与从表中读取记录相关的各种SQL语句和相应的MongoDB语句。
Note
The find() method always includes the _id field in the returned documents unless specifically excluded through projection. find()方法总是在返回的文档中包含_id字段,除非通过投影特别排除。Some of the SQL queries below may include an 下面的一些SQL查询可能包含一个_id field to reflect this, even if the field is not included in the corresponding find() query._id字段来反映这一点,即使该字段未包含在相应的find()查询中。
SQL SELECT | find()语句 |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-or- |
|
-or- |
|
|
|
|
|
or |
|
or |
|
or |
|
|
|
or |
|
|
|
|
For more information on the methods and operators used, see有关所用方法和运算符的更多信息,请参阅
Update Records更新记录
The following table presents the various SQL statements related to updating existing records in tables and the corresponding MongoDB statements.下表显示了与更新表中现有记录相关的各种SQL语句和相应的MongoDB语句。
SQL Update | MongoDB updateMany() |
|---|---|
|
|
|
|
For more information on the method and operators used in the examples, see:有关示例中使用的方法和运算符的更多信息,请参阅:
Delete Records删除记录
The following table presents the various SQL statements related to deleting records from tables and the corresponding MongoDB statements.下表显示了与从表中删除记录相关的各种SQL语句和相应的MongoDB语句。
SQL Delete | MongoDB deleteMany() |
|---|---|
|
|
|
|
For more information, see 有关更多信息,请参阅db.collection.deleteMany().db.collection.deleteMany()。