進(jìn)入MongoDB Shell
進(jìn)入MongoDB的安裝目錄的bin目錄下,執(zhí)行./mongo進(jìn)入MongoDB Shell。
如下如所示:

MongoDB Shell
顯示所有的數(shù)據(jù)庫(kù)
show dbs

顯示所有的數(shù)據(jù)庫(kù)
顯示當(dāng)前的數(shù)據(jù)庫(kù)
db

顯示當(dāng)前的數(shù)據(jù)庫(kù)
切換到指定的數(shù)據(jù)庫(kù)
use gcLog

切換到指定的數(shù)據(jù)庫(kù)
顯示所有的collection
show collections

顯示所有的collection
查詢指定collection中的數(shù)據(jù)
// 查詢名為gcLogItem的collection中的全部document
// pretty()用來(lái)格式化查詢結(jié)果為可讀
db.gcLogItem.find().pretty()

查詢指定collection中的數(shù)據(jù)
添加查詢條件
// 查詢查詢名為gcLogItem的collection中 gcType為FULL的全部document
db.gcLogItem.find({"gcType":"FULL"}).pretty()

添加查詢條件
限制查詢的條數(shù)
// 查詢符合條件的10條記錄
db.gcLogItem.find().limit(10).pretty()