连接数据库
示例如下 请根据自己的数据库ip和监听的端口号输入
mongo --host 192.168.3.81 --port 27017
切换数据库
use admin
db.auth("yourusername","yourpassword")
use yourdbname;
记录查询操作详情
db.setProfilingLevel(2);//记录所有的操作
db.setProfilingLevel(0);//不记录任何操作
db.setProfilingLevel(1,50);//记录大于50毫秒的操作
显示
{ "was" : 1, "slowms" : 50, "ok" : 1 }
即为成功
查看profile
db.getCollection('system.profile').find({})
分析 profile中mills较大的 command
假设分析发现查询 user 集合 的 username 和 userage 的 mills较大。
创建索引user集合 username 和 userage 的索引
db.user.createIndex({"username":1,"userage":1})
查看索引
db.user.getIndexes()
删除所有的索引
db.user.dropIndexes()
清空 profile
db.system.profile.drop()
Since this Handler is declared as an inner class, it may prevent the outer class from being garbage collected. If the Handler is using a Looper or MessageQueue for a thread other than the main thread, then there is no issue. If the Handler is using the Looper or MessageQueue of the main thread, you need to fix your Handler declaration, as follows: Declare the Handler as a static class; In the outer class, instantiate a WeakReference to the outer class and pass this object to your Handler when you instantiate the Handler; Make all references to members of the outer class using the WeakReference object.