SQL术语/概念 MongoDB术语/概念 解释/说明
database database 数据库
table collection 数据库表/集合
row document 数据记录行/文档
column field 数据字段/域
index index 索引
table joins   表连接,MongoDB不支持
primary key primary key 主键,MongoDB自动将_id字段设置为主键

通过下图实例,我们也可以更直观的了解Mongo中的一些概念:

MongoDB学习


 

实例

以下实例我们创建了数据库 runoob:

> use runoob
switched to db runoob
> db
runoob
> 

如果你想查看所有数据库,可以使用 show dbs 命令:

> show dbs
admin   0.000GB
config  0.000GB
local   0.000GB
> 

可以看到,我们刚创建的数据库 runoob 并不在数据库的列表中, 要显示它,我们需要向 runoob 数据库插入一些数据。

> db.runoob.insert({"name":"菜鸟教程"})
WriteResult({ "nInserted" : 1 })
> show dbs
admin   0.000GB
config  0.000GB
local   0.000GB
runoob  0.000GB

MongoDB 中默认的数据库为 test,如果你没有创建新的数据库,集合将存放在 test 数据库中。

 

相关文章:

  • 2021-05-06
  • 2021-05-14
  • 2021-07-06
猜你喜欢
  • 2021-04-08
  • 2021-09-20
  • 2021-06-28
相关资源
相似解决方案