mongo進程操作
導出數據:
mongoexport –db dbs –collection table –out ./users.json
導入數據:(–upsert:導入時有相同記錄的則覆蓋)
mongoimport –db dbs –collection table –file ./users.json –type json –upsert
備份單節點
mongodump –db dbs –out e:\bak
恢復單節點(-drop:恢復之前,刪除此數據庫下所有的集合)
mongorestore –db dbs –drop e:\back\dbs
索引
刪除索引:
db.table.dropIndex(索引名稱);
查詢索引:
db.system.indexes.find();
添加索引:
db.table.ensureIndex({‘xxx’: 1});
性能優化
開啓慢查詢監聽:
開啓數據庫監聽功能,記錄慢查詢:(結果保存在system.profile集合當中)
db.setProfilingLevel(1, 200);
數據庫命令serverStatus:
db.serverStatus();
重點查看幾個重要因數:
- globalLock.currentQueue.total
- men.resident
- globalLock.activeClients
globalLock.currentQueue.total
說明:如果值較大,說明系統中有許多的請求在等待鎖,同時說明併發影響了性能
men.resident
說明:如果超過了系統的內存說明系統內存過小,men.mapped的值大於系統內存,那麼針對數據庫的一些讀操作將會引起操作系統的缺頁錯誤。
globalLock.currentQueue.total
說明:表明當前正在進行讀寫操作客戶端的連接數。
free命令:
第二行,-buffers/cache反應的是被系統實際使用掉的內存,而+buffer/cache反映的是可以利用的內存總數。