database 數據庫
[]//代表參數
show tables//當前數據庫中的集合
show dbs//所有的數據庫
use [databasename] //add
db.dropDatabase() //remove
collection 集合
db.[collectionName].drop()//刪除當前庫中的指定集合
db.[collectionName].insert([json])//add插入了一條,這個集合就自動創建了
db.[collectionName].remove([json])//remove指定的文檔
db.[collectionName].find([json])//select
db.[collectionName].update([json],[json|{$set:json],[可填一個true代表查找不到時自動插入]})//update 第二個參數的兩值代表修改指定文檔的部分字段,而不是修改指定文檔的結構
demo
db.imocc_collection.update({c:1},{$set:{c:2}},false,true)
imocc_collection集合中所有【最後一個參數設置爲true就代表更新所有的文檔,默認爲false只修改第一個匹配的】c等於1的文檔,修改爲c等於2
index 索引
db.[collectionName].getIndexes()//指定集合的索引情況
db.[collectionName].ensureIndex([json])//添加索引
//db.imocc_collection.ensureIndex({x:1}) value爲1或負1 1代表正向排序,-1代表逆向排序 場景:`如,有一個登錄日誌庫,若用戶只關心最近一次登錄的日期,那麼,就可以用倒序來進行索引,這樣匹配的次數會少很多。`