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反映的是可以利用的内存总数。