1、wait lock
db.currentOp(
{
"waitingForLock" : true,
$or: [
{ "op" : { "$in" : [ "insert", "update", "remove" ] } },
{ "query.findandmodify": { $exists: true } }
]
}
)
2、cur_index
db.currentOp(
{
$or: [
{ op: "command", "query.createIndexes": { $exists: true } },
{ op: "insert", ns: /\.system\.indexes\b/ }
]
}
)
3、op_gte_2s
db.currentOp({"secs_running": {$gte: 2}});
4、op_collscan
db.currentOp({"planSummary" : "COLLSCAN"})
5、cur_ns_cnt
var s = db.currentOp(); db.cur_op_txt_cz.drop(); for(var i = 0; i<s.inprog.length;i++){ var ns_t = s.inprog[i].ns; var ns_plan = s.inprog[i].planSummary; db.cur_op_txt_cz.insert({"ns_name":ns_t,"planSummary":ns_plan}) }; db.cur_op_txt_cz.aggregate([{$group : {_id : {ns_name:"$ns_name",planSummary:"$planSummary"}, cnt : {$sum : 1}}}]);
6、cur_collscan_op
db.currentOp().inprog.forEach(function(item) {
if (item.planSummary == "COLLSCAN" && item.ns !== "local.oplog.rs") {
var tab_name = item["ns"];
print("na_name:", tab_name, " ", item.op, " ", JSON.stringify(item.client_s), " ", item.opid, " ", JSON.stringify(item.query));
}
});
7、tab_for_kill
db.currentOp().inprog.forEach(function(item) {
if (item.op == "query" && item.active && item.ns == "db_name.tb_name") {
{
print("kill_id: ", item.opid),
db.killOp(item.opid)
}
}
});
8、mongostat
mongostat -h 92.12.76.13:27001 -u shard_admin -p 'shard_admin@!2020' --authenticationDatabase=admin --humanReadable=true --discover --all 2
db.test.update(
{},
{$set: { "customerAliasNames.$[element1].aliasName" : "abcc","customerAliasNames.$[element2].aliasName" : "deff" } },
{
multi: true,
arrayFilters: [ { "element1.aliasName": { $eq: "abc" } } ,
{ "element2.aliasName": { $eq: "def" } } ]
}
)
10、碎片率
function getCollectionDiskSpaceFragRatio(dbname, coll) {
var res = db.getSiblingDB(dbname).runCommand({
collStats: coll
});
var totalStorageUnusedSize = 0;
var totalStorageSize = res['storageSize'] + res['totalIndexSize'];
Object.keys(res.indexDetails).forEach(function(key) {
var size = res['indexDetails'][key]['block-manager']['file bytes
available for reuse'];
print("index table " + key + " unused size: " +
size); totalStorageUnusedSize += size;
});
var size = res['wiredTiger']['block-manager']['file bytes available for reuse'];
print("collection table " + coll + " unused size: " + size);
totalStorageUnusedSize += size;
print("collection and index table total unused size: " +
totalStorageUnusedSize);
print("collection and index table total file size: " + totalStorageSize);
print("Fragmentation ratio: " + ((totalStorageUnusedSize * 100.0) /
totalStorageSize).toFixed(2) + "%");
12}
use xxxdb
db.getCollectionNames().forEach((c) => {print("\n\n" +
c); getCollectionDiskSpaceFragRatio(db.getName(),
c);});
--objectid时间查询
如何查找命令(此日期[2015-1-12]至此日期[2015-1-15]):
db.collection.find({_id:{$gt: ObjectId(Math.floor((new Date('2015/1/12'))/1000).toString(16) + "0000000000000000"), $lt: ObjectId(Math.floor((new Date('2015/1/15'))/1000).toString(16) + "0000000000000000")}}).pretty()
计算命令(此日期[2015-1-12]至此日期[2015-1-15]):
db.collection.count({_id:{$gt: ObjectId(Math.floor((new Date('2015/1/12'))/1000).toString(16) + "0000000000000000"), $lt: ObjectId(Math.floor((new Date('2015/1/15'))/1000).toString(16) + "0000000000000000")}})
删除命令(此日期[2015-1-12]至此日期[2015-1-15]):
db.collection.remove({_id:{$gt: ObjectId(Math.floor((new Date('2015/1/12'))/1000).toString(16) + "0000000000000000"), $lt: ObjectId(Math.floor((new Date('2015/1/15'))/1000).toString(16) + "0000000000000000")}})