mongodb 常用维护命令集查看数据库列表goluk:PRIMARY> show databases;.....local 42.058GB......test 0.078GBtrip 281.816GB查看数据库大小goluk:PRIMARY> db.stats();{ "db" : "test", "collections" : 3, "objects" : 5, "avgObjSize" : 60.8, "dataSize" : 304, "storageSize" : 20480, "numExtents" : 3, "indexes" : 1, "indexSize" : 8176, "fileSize" : 67108864, "nsSizeMB" : 16, "extentFreeList" : { "num" : 0, "totalSize" : 0 }, "dataFileVersion" : { "major" : 4, "minor" : 22 }, "ok" : 1}查看trip库表goluk:PRIMARY> use tripswitched to db tripgoluk:PRIMARY> show tables;inc_idssystem.indexes......查看表的统计信息goluk:PRIMARY> db.trip_track.stats();{ "ns" : "trip.trip_track", "count" : 9666824, "size" : 4794744704, "avgObjSize" : 496, "numExtents" : 24, "storageSize" : 7159508992, "lastExtentSize" : 1861685248, "paddingFactor" : 1, "paddingFactorNote" : "paddingFactor is unused and unmaintained in 3.0. It remains hard coded to 1.0 for compatibility only.", "userFlags" : 1, "capped" : false, "nindexes" : 5, "totalIndexSize" : 5580128176, "indexSizes" : { "_id_" : 356604416, "partid_1" : 1025090528, "partid_1_uploadtime_1" : 1200138688, "carid_1_partid_1" : 1796888576, "carid_1_uploadtime_1" : 1201405968 }, "ok" : 1}查看表大小goluk:PRIMARY> db.trip_track.totalSize();12739637168goluk:PRIMARY> db.trip_track2.totalSize();goluk:PRIMARY> db.trip_track_1.totalSize();58456562656goluk:PRIMARY> db.trip_track_2.totalSize();59122694080goluk:PRIMARY> db.trip_track_3.totalSize();64272991520查看当前执行的进程(语句) 执行 db.currentOp(); 获取opid: { "desc" : "conn2831006", "threadId" : "0xbeb3380", "connectionId" : 2831006, "opid" : 694360071, ......杀掉进程db.killOp(694360071)查找示例db.trip_track_1.find({'carid':'ssxxddd'}).limint(10);查看各个表名命令goluk:PRIMARY> show tables;inc_idssystem.indexestrip_baiducitycodetrip_carstrip_channeltrip_devicetrip_device_datausagetrip_grouptrip_ipctrip_live_videotrip_phone_historytrip_pictrip_propertiestrip_router_statetrip_tracktrip_track_1trip_track_2trip_track_3trip_track_4trip_track_5trip_track_parttrip_track_tabletrip_videotrip_weixin_relatrip_weixin_subupdate_goluk_mobileidupdate_goluk_modelupdate_ipc_version首先写个shell获取表名# cat show.sh#!/bin/shMONGO=/usr/local/bin/mongoDB=trip$MONGO生成执行语句sh show.sh |head -n -1 |tail -n +4 >s2.sql生成获取表大小语句for i in `cat s2.sql` ; do echo "db.$i.totalSize()" ;done执行获取表大小语句mongo生成最终数据goluk:PRIMARY> show dbs;......local 42.058GB......test 0.078GBtrip 311.802GB表 Byte MBtrip_track 12534166112 11,953.51trip_track_1 58456562656 55,748.52trip_track_2 59122694080 56,383.79trip_track_3 64272991520 61,295.50trip_track_4 95992970944 91,546.03trip_track_5 13836463920 13,195.48 09-29 08:44