1. 程式人生 > >mongodb常見管理命令

mongodb常見管理命令

----------1.複製資料庫

wind:PRIMARY> show dbs;
jinri  0.078GB
local  1.078GB
test   0.078GB
wind   0.078GB

wind:PRIMARY> use admin;
switched to db admin


db.runCommand(
{copydb : 1,
fromhost : "localhost",
fromdb : "wind",
todb : "snow"
}
);

#執行結果
wind:PRIMARY> use admin;
switched to db admin

wind:PRIMARY> db.runCommand(
... {copydb : 1,
... fromhost : "localhost",
... fromdb : "wind",
... todb : "snow"
... }
... );
{ "ok" : 1 }
wind:PRIMARY> show dbs;
jinri  0.078GB
local  1.078GB
snow   0.078GB
test   0.078GB
wind   0.078GB
wind:PRIMARY> use snow;
switched to db snow
wind:PRIMARY> show tables;
system.indexes
tblorders


wind:PRIMARY> use snow;
switched to db snow
wind:PRIMARY> db.tblorders.find().count();
3


-------2.重新命名集合

use admin;

db.runCommand(
{
renameCollection:"snow.tblorders",
to: "wind.tblbooks",
dropTarget: false
}
);


--case01:

wind:PRIMARY> use snow;
switched to db snow
wind:PRIMARY> show tables;
system.indexes
tblorders

wind:PRIMARY> use wind;
switched to db wind
wind:PRIMARY> show tables;
system.indexes
tblorders


wind:PRIMARY> use admin;
switched to db admin

wind:PRIMARY> 
wind:PRIMARY> db.runCommand(
... {
... renameCollection:"snow.tblorders",
... to: "wind.tblbooks",
... dropTarget: false
... }
... );
{ "ok" : 1 }
wind:PRIMARY> use snow;
switched to db snow
wind:PRIMARY> show tables;
system.indexes
wind:PRIMARY> use wind;
switched to db wind
wind:PRIMARY> show tables;
system.indexes
tblbooks
tblorders


--case02:


wind:PRIMARY> use wind;
switched to db wind
wind:PRIMARY> show tables;
system.indexes
tblbooks
tblorders
wind:PRIMARY> use snow;
switched to db snow
wind:PRIMARY> show tables;
system.indexes


use admin;

db.runCommand(
{
renameCollection:"wind.tblorders",
to: "snow.tblbooks",
dropTarget: true
}
);

wind:PRIMARY> use wind;
switched to db wind
wind:PRIMARY> show tables;
system.indexes
tblbooks
wind:PRIMARY> use snow;
switched to db snow
wind:PRIMARY> show tables;
system.indexes
tblbooks
wind:PRIMARY> use snow;
switched to db snow
wind:PRIMARY> show tables;
system.indexes
tblbooks


-------3.檢視資料庫和集合的統計資訊

db.stats();

wind:PRIMARY> db.tblorders.stats();
{
	"ns" : "jinri.tblorders",
	"count" : 5,
	"size" : 560,
	"avgObjSize" : 112,
	"numExtents" : 1,
	"storageSize" : 8192,
	"lastExtentSize" : 8192,
	"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" : 1,
	"totalIndexSize" : 8176,
	"indexSizes" : {
		"_id_" : 8176
	},
	"ok" : 1
}


wind:PRIMARY> db.stats();
{
	"db" : "jinri",  #資料庫名
	"collections" : 3, #collection的數量
	"objects" : 9,  #物件資料量
	"avgObjSize" : 90.66666666666667,  #物件平均大小
	"dataSize" : 816,  #資料大小
	"storageSize" : 20480,  #資料儲存大小包括預分配空間
	"numExtents" : 3,  #事件數量
	"indexes" : 1,  #索引數量
	"indexSize" : 8176,  #索引大小
	"fileSize" : 67108864,  #檔案大小
	"nsSizeMB" : 16,
	"extentFreeList" : {
		"num" : 0,
		"totalSize" : 0
	},
	"dataFileVersion" : {
		"major" : 4,
		"minor" : 22
	},
	"ok" : 1  #本次stats是否正常
}



---4.檢查資料庫

wind:PRIMARY> db.tblbooks.validate();
{
	"ns" : "snow.tblbooks",
	"datasize" : 336,
	"nrecords" : 3,
	"lastExtentSize" : 8192,
	"firstExtent" : "0:5000 ns:snow.tblbooks",
	"lastExtent" : "0:5000 ns:snow.tblbooks",
	"extentCount" : 1,
	"firstExtentDetails" : {
		"loc" : "0:5000",
		"xnext" : "null",
		"xprev" : "null",
		"nsdiag" : "snow.tblbooks",
		"size" : 8192,
		"firstRecord" : "0:50b0",
		"lastRecord" : "0:51b0"
	},
	"deletedCount" : 1,
	"deletedSize" : 7632,
	"nIndexes" : 1,
	"keysPerIndex" : {
		"snow.tblbooks.$_id_" : 3
	},
	"valid" : true,
	"errors" : [ ],
	"warning" : "Some checks omitted for speed. use {full:true} option to do more thorough scan.",
	"ok" : 1
}
wind:PRIMARY> 



wind:PRIMARY> db.tblbooks.validate(true);
{
	"ns" : "snow.tblbooks",
	"datasize" : 336,
	"nrecords" : 3,
	"lastExtentSize" : 8192,
	"firstExtent" : "0:5000 ns:snow.tblbooks",
	"lastExtent" : "0:5000 ns:snow.tblbooks",
	"extentCount" : 1,
	"extents" : [
		{
			"loc" : "0:5000",
			"xnext" : "null",
			"xprev" : "null",
			"nsdiag" : "snow.tblbooks",
			"size" : 8192,
			"firstRecord" : "0:50b0",
			"lastRecord" : "0:51b0"
		}
	],
	"firstExtentDetails" : {
		"loc" : "0:5000",
		"xnext" : "null",
		"xprev" : "null",
		"nsdiag" : "snow.tblbooks",
		"size" : 8192,
		"firstRecord" : "0:50b0",
		"lastRecord" : "0:51b0"
	},
	"objectsFound" : 3,
	"invalidObjects" : 0,
	"nQuantizedSize" : 3,
	"bytesWithHeaders" : 384,
	"bytesWithoutHeaders" : 336,
	"bytesBson" : 263,
	"deletedCount" : 1,
	"deletedSize" : 7632,
	"delBucketSizes" : [
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		1,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0
	],
	"nIndexes" : 1,
	"keysPerIndex" : {
		"snow.tblbooks.$_id_" : 3
	},
	"indexDetails" : {
		"snow.tblbooks.$_id_" : {
			
		}
	},
	"valid" : true,
	"errors" : [ ],
	"ok" : 1
}



---5.剖析mongodb主要解決資料庫慢的效能問題
剖析等級:
0:不剖析
1:只剖析速度慢的操作
2:剖析所有操作

wind:PRIMARY> use snow;
switched to db snow

wind:PRIMARY> show tables;
system.indexes
tblbooks

wind:PRIMARY> db.runCommand({profile:2,slows:100});
{ "was" : 0, "slowms" : 100, "ok" : 1 }

wind:PRIMARY> db.tblbooks.find();

{ "_id" : ObjectId("55c069cf0bef81df34afc6d3"), "orderno" : "1001", "pname" : "jinri", "scity" : "pek", "price" : 1650 }
{ "_id" : ObjectId("55c06dcd1449f1bbe0a56e9b"), "orderno" : "1002", "pname" : "jinri", "scity" : "pvg", "price" : 1750 }
{ "_id" : ObjectId("55c0701c9ee8e3a9b7f8109f"), "orderno" : "1189", "pname" : "ocpyang", "scity" : "ctu", "price" : 780 }


wind:PRIMARY> db.system.profile.find();
{ "op" : "query", "ns" : "snow.tblbooks", "query" : {  }, "ntoreturn" : 0, "ntoskip" : 0, "nscanned" : 0, "nscannedObjects" : 3, "keyUpdates" : 0, "writeConflicts" : 0, "numYield" : 0, "locks" : { "Global" : { "acquireCount" : { "r" : NumberLong(2) } }, "MMAPV1Journal" : { "acquireCount" : { "r" : NumberLong(1) } }, "Database" : { "acquireCount" : { "r" : NumberLong(1) } }, "Collection" : { "acquireCount" : { "R" : NumberLong(1) } } }, "nreturned" : 3, "responseLength" : 283, "millis" : 0, "execStats" : { "stage" : "COLLSCAN", "filter" : { "$and" : [ ] }, "nReturned" : 3, "executionTimeMillisEstimate" : 0, "works" : 5, "advanced" : 3, "needTime" : 1, "needFetch" : 0, "saveState" : 0, "restoreState" : 0, "isEOF" : 1, "invalidates" : 0, "direction" : "forward", "docsExamined" : 3 }, "ts" : ISODate("2015-08-06T05:28:23.407Z"), "client" : "127.0.0.1", "allUsers" : [ ], "user" : "" }
wind:PRIMARY> 


---6.評估查詢

wind:PRIMARY> db.tblbooks.find({"orderno" : {$in: ["1001","1189"]}});
{ "_id" : ObjectId("55c069cf0bef81df34afc6d3"), "orderno" : "1001", "pname" : "jinri", "scity" : "pek", "price" : 1650 }
{ "_id" : ObjectId("55c0701c9ee8e3a9b7f8109f"), "orderno" : "1189", "pname" : "ocpyang", "scity" : "ctu", "price" : 780 }



wind:PRIMARY> db.tblbooks.find({"orderno" : {$in: ["1001","1189"]}}).explain();
{
	"queryPlanner" : {
		"plannerVersion" : 1,
		"namespace" : "snow.tblbooks",
		"indexFilterSet" : false,
		"parsedQuery" : {
			"orderno" : {
				"$in" : [
					"1001",
					"1189"
				]
			}
		},
		"winningPlan" : {
			"stage" : "COLLSCAN",
			"filter" : {
				"orderno" : {
					"$in" : [
						"1001",
						"1189"
					]
				}
			},
			"direction" : "forward"
		},
		"rejectedPlans" : [ ]
	},
	"serverInfo" : {
		"host" : "mg02.atalas.com",
		"port" : 27017,
		"version" : "3.0.5",
		"gitVersion" : "8bc4ae20708dbb493cb09338d9e7be6698e4a3a3"
	},
	"ok" : 1
}
wind:PRIMARY> 



----7.診斷命令top
 use admin;

 db.runCommand({top : 1});


 wind:PRIMARY>  db.runCommand({top : 1});
{
	"totals" : {
		"note" : "all times in microseconds",
		"admin.system.roles" : {
			"total" : {
				"time" : 198,
				"count" : 1
			},
			"readLock" : {
				"time" : 198,
				"count" : 1
			},
			"writeLock" : {
				"time" : 0,
				"count" : 0
			},
			"queries" : {
				"time" : 198,
				"count" : 1
			},
			"getmore" : {
				"time" : 0,
				"count" : 0
			},
			"insert" : {
				"time" : 0,
				"count" : 0
			},
			"update" : {
				"time" : 0,
				"count" : 0
			},
			"remove" : {
				"time" : 0,
				"count" : 0
			},
			"commands" : {
				"time" : 0,
				"count" : 0
			}
		},
		"admin.system.version" : {
			"total" : {
				"time" : 19,
				"count" : 1
			},
			"readLock" : {
				"time" : 19,
				"count" : 1
			},
			"writeLock" : {
				"time" : 0,
				"count" : 0
			},
			"queries" : {
				"time" : 19,
				"count" : 1
			},
			"getmore" : {
				"time" : 0,
				"count" : 0
			},
			"insert" : {
				"time" : 0,
				"count" : 0
			},
			"update" : {
				"time" : 0,
				"count" : 0
			},
			"remove" : {
				"time" : 0,
				"count" : 0
			},
			"commands" : {
				"time" : 0,
				"count" : 0
			}
		},
		"jinri.system.indexes" : {
			"total" : {
				"time" : 100018,
				"count" : 41799
			},
			"readLock" : {
				"time" : 100017,
				"count" : 41798
			},
			"writeLock" : {
				"time" : 1,
				"count" : 1
			},
			"queries" : {
				"time" : 1,
				"count" : 1
			},
			"getmore" : {
				"time" : 0,
				"count" : 0
			},
			"insert" : {
				"time" : 0,
				"count" : 0
			},
			"update" : {
				"time" : 0,
				"count" : 0
			},
			"remove" : {
				"time" : 0,
				"count" : 0
			},
			"commands" : {
				"time" : 0,
				"count" : 0
			}
		},
		"jinri.system.namespaces" : {
			"total" : {
				"time" : 103262,
				"count" : 41799
			},
			"readLock" : {
				"time" : 103260,
				"count" : 41798
			},
			"writeLock" : {
				"time" : 2,
				"count" : 1
			},
			"queries" : {
				"time" : 2,
				"count" : 1
			},
			"getmore" : {
				"time" : 0,
				"count" : 0
			},
			"insert" : {
				"time" : 0,
				"count" : 0
			},
			"update" : {
				"time" : 0,
				"count" : 0
			},
			"remove" : {
				"time" : 0,
				"count" : 0
			},
			"commands" : {
				"time" : 0,
				"count" : 0
			}
		},
		"jinri.tblorders" : {
			"total" : {
				"time" : 157052,
				"count" : 41801
			},
			"readLock" : {
				"time" : 157040,
				"count" : 41800
			},
			"writeLock" : {
				"time" : 12,
				"count" : 1
			},
			"queries" : {
				"time" : 187,
				"count" : 2
			},
			"getmore" : {
				"time" : 0,
				"count" : 0
			},
			"insert" : {
				"time" : 0,
				"count" : 0
			},
			"update" : {
				"time" : 0,
				"count" : 0
			},
			"remove" : {
				"time" : 0,
				"count" : 0
			},
			"commands" : {
				"time" : 47,
				"count" : 1
			}
		},
		"local.me" : {
			"total" : {
				"time" : 117360,
				"count" : 41800
			},
			"readLock" : {
				"time" : 117358,
				"count" : 41799
			},
			"writeLock" : {
				"time" : 2,
				"count" : 1
			},
			"queries" : {
				"time" : 23,
				"count" : 2
			},
			"getmore" : {
				"time" : 0,
				"count" : 0
			},
			"insert" : {
				"time" : 0,
				"count" : 0
			},
			"update" : {
				"time" : 0,
				"count" : 0
			},
			"remove" : {
				"time" : 0,
				"count" : 0
			},
			"commands" : {
				"time" : 0,
				"count" : 0
			}
		},
		"local.oplog.rs" : {
			"total" : {
				"time" : 9624292,
				"count" : 239276
			},
			"readLock" : {
				"time" : 9624175,
				"count" : 239273
			},
			"writeLock" : {
				"time" : 117,
				"count" : 3
			},
			"queries" : {
				"time" : 713,
				"count" : 6
			},
			"getmore" : {
				"time" : 9453520,
				"count" : 197469
			},
			"insert" : {
				"time" : 0,
				"count" : 0
			},
			"update" : {
				"time" : 0,
				"count" : 0
			},
			"remove" : {
				"time" : 0,
				"count" : 0
			},
			"commands" : {
				"time" : 0,
				"count" : 0
			}
		},
		"local.replset.minvalid" : {
			"total" : {
				"time" : 148232,
				"count" : 41814
			},
			"readLock" : {
				"time" : 146658,
				"count" : 41800
			},
			"writeLock" : {
				"time" : 1574,
				"count" : 14
			},
			"queries" : {
				"time" : 1,
				"count" : 1
			},
			"getmore" : {
				"time" : 0,
				"count" : 0
			},
			"insert" : {
				"time" : 0,
				"count" : 0
			},
			"update" : {
				"time" : 0,
				"count" : 0
			},
			"remove" : {
				"time" : 0,
				"count" : 0
			},
			"commands" : {
				"time" : 0,
				"count" : 0
			}
		},
		"local.startup_log" : {
			"total" : {
				"time" : 100225,
				"count" : 41799
			},
			"readLock" : {
				"time" : 100223,
				"count" : 41798
			},
			"writeLock" : {
				"time" : 2,
				"count" : 1
			},
			"queries" : {
				"time" : 2,
				"count" : 1
			},
			"getmore" : {
				"time" : 0,
				"count" : 0
			},
			"insert" : {
				"time" : 0,
				"count" : 0
			},
			"update" : {
				"time" : 0,
				"count" : 0
			},
			"remove" : {
				"time" : 0,
				"count" : 0
			},
			"commands" : {
				"time" : 0,
				"count" : 0
			}
		},
		"local.system.indexes" : {
			"total" : {
				"time" : 86724,
				"count" : 41799
			},
			"readLock" : {
				"time" : 86723,
				"count" : 41798
			},
			"writeLock" : {
				"time" : 1,
				"count" : 1
			},
			"queries" : {
				"time" : 1,
				"count" : 1
			},
			"getmore" : {
				"time" : 0,
				"count" : 0
			},
			"insert" : {
				"time" : 0,
				"count" : 0
			},
			"update" : {
				"time" : 0,
				"count" : 0
			},
			"remove" : {
				"time" : 0,
				"count" : 0
			},
			"commands" : {
				"time" : 0,
				"count" : 0
			}
		},
		"local.system.namespaces" : {
			"total" : {
				"time" : 90343,
				"count" : 41799
			},
			"readLock" : {
				"time" : 90342,
				"count" : 41798
			},
			"writeLock" : {
				"time" : 1,
				"count" : 1
			},
			"queries" : {
				"time" : 1,
				"count" : 1
			},
			"getmore" : {
				"time" : 0,
				"count" : 0
			},
			"insert" : {
				"time" : 0,
				"count" : 0
			},
			"update" : {
				"time" : 0,
				"count" : 0
			},
			"remove" : {
				"time" : 0,
				"count" : 0
			},
			"commands" : {
				"time" : 0,
				"count" : 0
			}
		},
		"local.system.replset" : {
			"total" : {
				"time" : 88247,
				"count" : 41802
			},
			"readLock" : {
				"time" : 86882,
				"count" : 41799
			},
			"writeLock" : {
				"time" : 1365,
				"count" : 3
			},
			"queries" : {
				"time" : 28,
				"count" : 2
			},
			"getmore" : {
				"time" : 0,
				"count" : 0
			},
			"insert" : {
				"time" : 0,
				"count" : 0
			},
			"update" : {
				"time" : 0,
				"count" : 0
			},
			"remove" : {
				"time" : 0,
				"count" : 0
			},
			"commands" : {
				"time" : 0,
				"count" : 0
			}
		},
		"snow" : {
			"total" : {
				"time" : 435,
				"count" : 1
			},
			"readLock" : {
				"time" : 0,
				"count" : 0
			},
			"writeLock" : {
				"time" : 435,
				"count" : 1
			},
			"queries" : {
				"time" : 0,
				"count" : 0
			},
			"getmore" : {
				"time" : 0,
				"count" : 0
			},
			"insert" : {
				"time" : 0,
				"count" : 0
			},
			"update" : {
				"time" : 0,
				"count" : 0
			},
			"remove" : {
				"time" : 0,
				"count" : 0
			},
			"commands" : {
				"time" : 435,
				"count" : 1
			}
		},
		"snow.system.indexes" : {
			"total" : {
				"time" : 3893,
				"count" : 1057
			},
			"readLock" : {
				"time" : 3893,
				"count" : 1057
			},
			"writeLock" : {
				"time" : 0,
				"count" : 0
			},
			"queries" : {
				"time" : 0,
				"count" : 0
			},
			"getmore" : {
				"time" : 0,
				"count" : 0
			},
			"insert" : {
				"time" : 0,
				"count" : 0
			},
			"update" : {
				"time" : 0,
				"count" : 0
			},
			"remove" : {
				"time" : 0,
				"count" : 0
			},
			"commands" : {
				"time" : 0,
				"count" : 0
			}
		},
		"snow.system.namespaces" : {
			"total" : {
				"time" : 3249,
				"count" : 1057
			},
			"readLock" : {
				"time" : 3249,
				"count" : 1057
			},
			"writeLock" : {
				"time" : 0,
				"count" : 0
			},
			"queries" : {
				"time" : 0,
				"count" : 0
			},
			"getmore" : {
				"time" : 0,
				"count" : 0
			},
			"insert" : {
				"time" : 0,
				"count" : 0
			},
			"update" : {
				"time" : 0,
				"count" : 0
			},
			"remove" : {
				"time" : 0,
				"count" : 0
			},
			"commands" : {
				"time" : 0,
				"count" : 0
			}
		},
		"snow.system.profile" : {
			"total" : {
				"time" : 2367,
				"count" : 106
			},
			"readLock" : {
				"time" : 2367,
				"count" : 106
			},
			"writeLock" : {
				"time" : 0,
				"count" : 0
			},
			"queries" : {
				"time" : 97,
				"count" : 1
			},
			"getmore" : {
				"time" : 0,
				"count" : 0
			},
			"insert" : {
				"time" : 0,
				"count" : 0
			},
			"update" : {
				"time" : 0,
				"count" : 0
			},
			"remove" : {
				"time" : 0,
				"count" : 0
			},
			"commands" : {
				"time" : 0,
				"count" : 0
			}
		},
		"snow.tblbooks" : {
			"total" : {
				"time" : 16310,
				"count" : 891
			},
			"readLock" : {
				"time" : 16310,
				"count" : 891
			},
			"writeLock" : {
				"time" : 0,
				"count" : 0
			},
			"queries" : {
				"time" : 945,
				"count" : 4
			},
			"getmore" : {
				"time" : 0,
				"count" : 0
			},
			"insert" : {
				"time" : 0,
				"count" : 0
			},
			"update" : {
				"time" : 0,
				"count" : 0
			},
			"remove" : {
				"time" : 0,
				"count" : 0
			},
			"commands" : {
				"time" : 164,
				"count" : 2
			}
		},
		"snow.tblorders" : {
			"total" : {
				"time" : 47,
				"count" : 2
			},
			"readLock" : {
				"time" : 47,
				"count" : 2
			},
			"writeLock" : {
				"time" : 0,
				"count" : 0
			},
			"queries" : {
				"time" : 0,
				"count" : 0
			},
			"getmore" : {
				"time" : 0,
				"count" : 0
			},
			"insert" : {
				"time" : 0,
				"count" : 0
			},
			"update" : {
				"time" : 0,
				"count" : 0
			},
			"remove" : {
				"time" : 0,
				"count" : 0
			},
			"commands" : {
				"time" : 47,
				"count" : 2
			}
		},
		"test.$cmd" : {
			"total" : {
				"time" : 11,
				"count" : 1
			},
			"readLock" : {
				"time" : 11,
				"count" : 1
			},
			"writeLock" : {
				"time" : 0,
				"count" : 0
			},
			"queries" : {
				"time" : 0,
				"count" : 0
			},
			"getmore" : {
				"time" : 0,
				"count" : 0
			},
			"insert" : {
				"time" : 0,
				"count" : 0
			},
			"update" : {
				"time" : 0,
				"count" : 0
			},
			"remove" : {
				"time" : 0,
				"count" : 0
			},
			"commands" : {
				"time" : 0,
				"count" : 0
			}
		},
		"test.system.indexes" : {
			"total" : {
				"time" : 104814,
				"count" : 41493
			},
			"readLock" : {
				"time" : 104814,
				"count" : 41493
			},
			"writeLock" : {
				"time" : 0,
				"count" : 0
			},
			"queries" : {
				"time" : 0,
				"count" : 0
			},
			"getmore" : {
				"time" : 0,
				"count" : 0
			},
			"insert" : {
				"time" : 0,
				"count" : 0
			},
			"update" : {
				"time" : 0,
				"count" : 0
			},
			"remove" : {
				"time" : 0,
				"count" : 0
			},
			"commands" : {
				"time" : 0,
				"count" : 0
			}
		},
		"test.system.namespaces" : {
			"total" : {
				"time" : 110821,
				"count" : 41493
			},
			"readLock" : {
				"time" : 110821,
				"count" : 41493
			},
			"writeLock" : {
				"time" : 0,
				"count" : 0
			},
			"queries" : {
				"time" : 0,
				"count" : 0
			},
			"getmore" : {
				"time" : 0,
				"count" : 0
			},
			"insert" : {
				"time" : 0,
				"count" : 0
			},
			"update" : {
				"time" : 0,
				"count" : 0
			},
			"remove" : {
				"time" : 0,
				"count" : 0
			},
			"commands" : {
				"time" : 0,
				"count" : 0
			}
		},
		"test.tblorders" : {
			"total" : {
				"time" : 263178,
				"count" : 41510
			},
			"readLock" : {
				"time" : 131753,
				"count" : 41507
			},
			"writeLock" : {
				"time" : 131425,
				"count" : 3
			},
			"queries" : {
				"time" : 1216,
				"count" : 13
			},
			"getmore" : {
				"time" : 0,
				"count" : 0
			},
			"insert" : {
				"time" : 0,
				"count" : 0
			},
			"update" : {
				"time" : 0,
				"count" : 0
			},
			"remove" : {
				"time" : 0,
				"count" : 0
			},
			"commands" : {
				"time" : 0,
				"count" : 0
			}
		},
		"wind.$cmd" : {
			"total" : {
				"time" : 15,
				"count" : 1
			},
			"readLock" : {
				"time" : 15,
				"count" : 1
			},
			"writeLock" : {
				"time" : 0,
				"count" : 0
			},
			"queries" : {
				"time" : 0,
				"count" : 0
			},
			"getmore" : {
				"time" : 0,
				"count" : 0
			},
			"insert" : {
				"time" : 0,
				"count" : 0
			},
			"update" : {
				"time" : 0,
				"count" : 0
			},
			"remove" : {
				"time" : 0,
				"count" : 0
			},
			"commands" : {
				"time" : 0,
				"count" : 0
			}
		},
		"wind.system.indexes" : {
			"total" : {
				"time" : 166903,
				"count" : 41455
			},
			"readLock" : {
				"time" : 166903,
				"count" : 41455
			},
			"writeLock" : {
				"time" : 0,
				"count" : 0
			},
			"queries" : {
				"time" : 0,
				"count" : 0
			},
			"getmore" : {
				"time" : 0,
				"count" : 0
			},
			"insert" : {
				"time" : 0,
				"count" : 0
			},
			"update" : {
				"time" : 0,
				"count" : 0
			},
			"remove" : {
				"time" : 0,
				"count" : 0
			},
			"commands" : {
				"time" : 0,
				"count" : 0
			}
		},
		"wind.system.namespaces" : {
			"total" : {
				"time" : 131388,
				"count" : 41455
			},
			"readLock" : {
				"time" : 131388,
				"count" : 41455
			},
			"writeLock" : {
				"time" : 0,
				"count" : 0
			},
			"queries" : {
				"time" : 0,
				"count" : 0
			},
			"getmore" : {
				"time" : 0,
				"count" : 0
			},
			"insert" : {
				"time" : 0,
				"count" : 0
			},
			"update" : {
				"time" : 0,
				"count" : 0
			},
			"remove" : {
				"time" : 0,
				"count" : 0
			},
			"commands" : {
				"time" : 0,
				"count" : 0
			}
		},
		"wind.tblbooks" : {
			"total" : {
				"time" : 5455,
				"count" : 944
			},
			"readLock" : {
				"time" : 5455,
				"count" : 944
			},
			"writeLock" : {
				"time" : 0,
				"count" : 0
			},
			"queries" : {
				"time" : 0,
				"count" : 0
			},
			"getmore" : {
				"time" : 0,
				"count" : 0
			},
			"insert" : {
				"time" : 0,
				"count" : 0
			},
			"update" : {
				"time" : 0,
				"count" : 0
			},
			"remove" : {
				"time" : 0,
				"count" : 0
			},
			"commands" : {
				"time" : 0,
				"count" : 0
			}
		}
	},
	"ok" : 1
}
wind:PRIMARY> 



-------8.db.serverStatus();


wind:PRIMARY> db.serverStatus()
{
	"host" : "mg02.atalas.com",
	"version" : "3.0.5",  #版本號
	"process" : "mongod",
	"pid" : NumberLong(3429),
	"uptime" : 169041, #啟動時間
	"uptimeMillis" : NumberLong(169040644),
	"uptimeEstimate" : 133689,
	"localTime" : ISODate("2015-08-06T06:03:51.049Z"),
	"asserts" : {
		"regular" : 0,
		"warning" : 0,
		"msg" : 0,
		"user" : 1210,
		"rollovers" : 0
	},
	"backgroundFlushing" : {
		"flushes" : 2817,
		"total_ms" : 210,
		"average_ms" : 0.07454739084132056,
		"last_ms" : 0,
		"last_finished" : ISODate("2015-08-06T06:03:34.595Z")
	},
	"connections" : {
		"current" : 5, #當前活動連線量
		"available" : 4995,  #剩餘的空閒連線資料量
		"totalCreated" : NumberLong(11085)
	},
	"cursors" : {
		"note" : "deprecated, use server status metrics",
		"clientCursors_size" : 1,
		"totalOpen" : 1,
		"pinned" : 0,
		"totalNoTimeout" : 0,
		"timedOut" : 1
	},
	"dur" : {
		"commits" : 29,
		"journaledMB" : 0,
		"writeToDataFilesMB" : 0,
		"compression" : 0,
		"commitsInWriteLock" : 0,
		"earlyCommits" : 0,
		"timeMs" : {
			"dt" : 3045,
			"prepLogBuffer" : 0,
			"writeToJournal" : 0,
			"writeToDataFiles" : 0,
			"remapPrivateView" : 0,
			"commits" : 0,
			"commitsInWriteLock" : 0
		}
	},
	"extra_info" : {
		"note" : "fields vary by platform",
		"heap_usage_bytes" : 63725680,
		"page_faults" : 5
	},
	"globalLock" : {
		"totalTime" : NumberLong("169040646000"),
		"currentQueue" : {
			"total" : 0,  #當前全部佇列量
			"readers" : 0, #讀請求佇列量
			"writers" : 0 #寫請求佇列量
		},
		"activeClients" : {
			"total" : 18,  #當前所有的客戶端連線量
			"readers" : 0,  #客戶端讀請求量
			"writers" : 0  #客戶端寫請求量
		}
	},
	"locks" : {
		"Global" : {
			"acquireCount" : {
				"r" : NumberLong(1779553),
				"w" : NumberLong(60),
				"R" : NumberLong(1),
				"W" : NumberLong(18)
			},
			"acquireWaitCount" : {
				"r" : NumberLong(2)
			},
			"timeAcquiringMicros" : {
				"r" : NumberLong(805)
			}
		},
		"MMAPV1Journal" : {
			"acquireCount" : {
				"r" : NumberLong(889742),
				"w" : NumberLong(154),
				"R" : NumberLong(1585585),
				"W" : NumberLong(2)
			},
			"acquireWaitCount" : {
				"w" : NumberLong(1),
				"R" : NumberLong(4)
			},
			"timeAcquiringMicros" : {
				"w" : NumberLong(1263),
				"R" : NumberLong(289607)
			}
		},
		"Database" : {
			"acquireCount" : {
				"r" : NumberLong(889714),
				"w" : NumberLong(22),
				"R" : NumberLong(30),
				"W" : NumberLong(38)
			}
		},
		"Collection" : {
			"acquireCount" : {
				"R" : NumberLong(679060),
				"W" : NumberLong(14)
			}
		},
		"Metadata" : {
			"acquireCount" : {
				"R" : NumberLong(2),
				"W" : NumberLong(21)
			}
		},
		"oplog" : {
			"acquireCount" : {
				"w" : NumberLong(8),
				"R" : NumberLong(244592)
			},
			"acquireWaitCount" : {
				"R" : NumberLong(2)
			},
			"timeAcquiringMicros" : {
				"R" : NumberLong(150)
			}
		}
	},
	"network" : {
		"bytesIn" : 25142718,  #傳送給此伺服器的資料量單位byte
		"bytesOut" : 26860998, #此伺服器發出的資料量單位byte
		"numRequests" : 199261  #傳送個此伺服器的請求量
	},
	"opcounters" : {
		"insert" : 1,  #插入操作的量
		"query" : 30,  #查詢操作的量
		"update" : 0,  #更新操作的量
		"delete" : 0,  #刪除操作的量
		"getmore" : 33093,
		"command" : 166140  #其他操作量
	},
	"opcountersRepl" : {
		"insert" : 3,
		"query" : 0,
		"update" : 0,
		"delete" : 0,
		"getmore" : 0,
		"command" : 2
	},
	"repl" : {
		"setName" : "wind",
		"setVersion" : 3,
		"ismaster" : true,
		"secondary" : false,
		"hosts" : [
			"192.168.50.120:27017",
			"192.168.50.130:27017",
			"192.168.50.110:27017"
		],
		"primary" : "192.168.50.120:27017",
		"me" : "192.168.50.120:27017",
		"electionId" : ObjectId("55c06f853aa8bfc653e166f5"),
		"rbid" : 1644540276
	},
	"storageEngine" : {
		"name" : "mmapv1"
	},
	"writeBacksQueued" : false,
	"mem" : {
		"bits" : 64,  #64位系統
		"resident" : 118,  #佔用的實體記憶體量
		"virtual" : 3607,  #虛擬記憶體量
		"supported" : true,  #是否支援記憶體擴充套件
		"mapped" : 1424,
		"mappedWithJournal" : 2848
	},
	"metrics" : {
		"commands" : {
			"_isSelf" : {
				"failed" : NumberLong(0),
				"total" : NumberLong(7)
			},
			"availableQueryOptions" : {
				"failed" : NumberLong(0),
				"total" : NumberLong(1)
			},
			"collStats" : {
				"failed" : NumberLong(2),
				"total" : NumberLong(3)
			},
			"copydb" : {
				"failed" : NumberLong(0),
				"total" : NumberLong(1)
			},
			"count" : {
				"failed" : NumberLong(0),
				"total" : NumberLong(2)
			},
			"create" : {
				"failed" : NumberLong(0),
				"total" : NumberLong(2)
			},
			"dbStats" : {
				"failed" : NumberLong(0),
				"total" : NumberLong(2)
			},
			"explain" : {
				"failed" : NumberLong(0),
				"total" : NumberLong(2)
			},
			"getLog" : {
				"failed" : NumberLong(0),
				"total" : NumberLong(11)
			},
			"insert" : {
				"failed" : NumberLong(0),
				"total" : NumberLong(1)
			},
			"isMaster" : {
				"failed" : NumberLong(0),
				"total" : NumberLong(2)
			},
			"listCollections" : {
				"failed" : NumberLong(0),
				"total" : NumberLong(25)
			},
			"listDatabases" : {
				"failed" : NumberLong(0),
				"total" : NumberLong(5)
			},
			"listIndexes" : {
				"failed" : NumberLong(0),
				"total" : NumberLong(1)
			},
			"profile" : {
				"failed" : NumberLong(0),
				"total" : NumberLong(1)
			},
			"renameCollection" : {
				"failed" : NumberLong(0),
				"total" : NumberLong(2)
			},
			"replSetElect" : {
				"failed" : NumberLong(0),
				"total" : NumberLong(1)
			},
			"replSetFresh" : {
				"failed" : NumberLong(0),
				"total" : NumberLong(3)
			},
			"replSetGetConfig" : {
				"failed" : NumberLong(0),
				"total" : NumberLong(1)
			},
			"replSetGetStatus" : {
				"failed" : NumberLong(0),
				"total" : NumberLong(119)
			},
			"replSetHeartbeat" : {
				"failed" : NumberLong(3),
				"total" : NumberLong(165912)
			},
			"replSetUpdatePosition" : {
				"failed" : NumberLong(0),
				"total" : NumberLong(22)
			},
			"serverStatus" : {
				"failed" : NumberLong(0),
				"total" : NumberLong(1)
			},
			"top" : {
				"failed" : NumberLong(0),
				"total" : NumberLong(1)
			},
			"usersInfo" : {
				"failed" : NumberLong(0),
				"total" : NumberLong(1)
			},
			"validate" : {
				"failed" : NumberLong(1),
				"total" : NumberLong(3)
			},
			"whatsmyuri" : {
				"failed" : NumberLong(0),
				"total" : NumberLong(11)
			}
		},
		"cursor" : {
			"timedOut" : NumberLong(1),
			"open" : {
				"noTimeout" : NumberLong(0),
				"pinned" : NumberLong(0),
				"total" : NumberLong(1)
			}
		},
		"document" : {
			"deleted" : NumberLong(0),
			"inserted" : NumberLong(1),
			"returned" : NumberLong(48),
			"updated" : NumberLong(0)
		},
		"getLastError" : {
			"wtime" : {
				"num" : 0,
				"totalMillis" : 0
			},
			"wtimeouts" : NumberLong(0)
		},
		"operation" : {
			"fastmod" : NumberLong(0),
			"idhack" : NumberLong(0),
			"scanAndOrder" : NumberLong(0),
			"writeConflicts" : NumberLong(0)
		},
		"queryExecutor" : {
			"scanned" : NumberLong(3),
			"scannedObjects" : NumberLong(48)
		},
		"record" : {
			"moves" : NumberLong(0)
		},
		"repl" : {
			"apply" : {
				"batches" : {
					"num" : 7,
					"totalMillis" : 309
				},
				"ops" : NumberLong(5)
			},
			"buffer" : {
				"count" : NumberLong(0),
				"maxSizeBytes" : 268435456,
				"sizeBytes" : NumberLong(0)
			},
			"network" : {
				"bytes" : NumberLong(7799),
				"getmores" : {
					"num" : 201,
					"totalMillis" : 1021022
				},
				"ops" : NumberLong(7),
				"readersCreated" : NumberLong(1)
			},
			"preload" : {
				"docs" : {
					"num" : 0,
					"totalMillis" : 0
				},
				"indexes" : {
					"num" : 3,
					"totalMillis" : 0
				}
			}
		},
		"storage" : {
			"freelist" : {
				"search" : {
					"bucketExhausted" : NumberLong(0),
					"requests" : NumberLong(48),
					"scanned" : NumberLong(0)
				}
			}
		},
		"ttl" : {
			"deletedDocuments" : NumberLong(0),
			"passes" : NumberLong(2817)
		}
	},
	"ok" : 1
}
wind:PRIMARY> 






-------9.檢視複製狀態

wind:PRIMARY> rs.status();
{
	"set" : "wind",
	"date" : ISODate("2015-08-06T06:16:30.954Z"),
	"myState" : 1,
	"members" : [
		{
			"_id" : 1,
			"name" : "192.168.50.120:27017",
			"health" : 1, #1表示正常,0表示異常
			"state" : 1,  #1表示primary ;2表明是secondary
			"stateStr" : "PRIMARY", #角色是主庫
			"uptime" : 169800, #啟動時間
			"optime" : Timestamp(1438835748, 1),
			"optimeDate" : ISODate("2015-08-06T04:35:48Z"),
			"electionTime" : Timestamp(1438674821, 1),
			"electionDate" : ISODate("2015-08-04T07:53:41Z"),
			"configVersion" : 3,
			"self" : true
		},
		{
			"_id" : 2,
			"name" : "192.168.50.130:27017",
			"health" : 1,  #1表示正常,0表示異常
			"state" : 2,  #1表示primary ;2表明是secondary
			"stateStr" : "SECONDARY",
			"uptime" : 164401,
			"optime" : Timestamp(1438835748, 1),
			"optimeDate" : ISODate("2015-08-06T04:35:48Z"),
			"lastHeartbeat" : ISODate("2015-08-06T06:16:30.604Z"),
			"lastHeartbeatRecv" : ISODate("2015-08-06T06:16:30.604Z"),
			"pingMs" : 1,
			"syncingTo" : "192.168.50.110:27017",
			"configVersion" : 3
		},
		{
			"_id" : 3,
			"name" : "192.168.50.110:27017",
			"health" : 1,   #1表示正常,0表示異常
			"state" : 2,   #1表示primary ;2表明是secondary
			"stateStr" : "SECONDARY",
			"uptime" : 168113,
			"optime" : Timestamp(1438835748, 1),
			"optimeDate" : ISODate("2015-08-06T04:35:48Z"),
			"lastHeartbeat" : ISODate("2015-08-06T06:16:30.581Z"),
			"lastHeartbeatRecv" : ISODate("2015-08-06T06:16:30.581Z"),
			"pingMs" : 1,
			"syncingTo" : "192.168.50.120:27017",
			"configVersion" : 3
		}
	],
	"ok" : 1
}
wind:PRIMARY>