进入MongoDB Shell
进入MongoDB的安装目录的bin目录下,执行./mongo进入MongoDB Shell。
如下如所示:

MongoDB Shell
显示所有的数据库
show dbs

显示所有的数据库
显示当前的数据库
db

显示当前的数据库
切换到指定的数据库
use gcLog

切换到指定的数据库
显示所有的collection
show collections

显示所有的collection
查询指定collection中的数据
// 查询名为gcLogItem的collection中的全部document
// pretty()用来格式化查询结果为可读
db.gcLogItem.find().pretty()

查询指定collection中的数据
添加查询条件
// 查询查询名为gcLogItem的collection中 gcType为FULL的全部document
db.gcLogItem.find({"gcType":"FULL"}).pretty()

添加查询条件
限制查询的条数
// 查询符合条件的10条记录
db.gcLogItem.find().limit(10).pretty()
