MongoDB Shell是MongoDB自带的交互式Javascript shell,用来对MongoDB进行操作和管理的交互式环境。
进入MongoDB后台后,默认会链接到 test文档(数据库):
# mongo
MongoDB shell version v3.6.4
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.6.4
Welcome to the MongoDB shell.
由于它是一个JavaScript shell,可以运行一些简单的算术运算:
> 4+4
8
>
现在我们插入一些简单的数据,并对插入的数据进行检索:
> db.appblog.insert({x:10})
WriteResult({ "nInserted" : 1 })
> db.appblog.find()
{ "_id" : ObjectId("5aead830134346012ef0f4bc"), "x" : 10 }
>
第一个命令将数字 10 插入到 appblog 集合的 x 字段中。




