mongodb的shell脚本

#################

 

重定向输入mongo脚本:

#! /bin/bash
 
mongo --username root  --password 123456 --host 10.10.10.10 --port 27017 --authenticationDatabase admin <<EOF
use apple;
db.currentOp();
EOF

 

转义$:

shell中使用mongodb的时候,如果需要查询条件$,则需要转义$,因为$字符在shell中是变量的意思:

 

#! /bin/bash
 
mongo --username root  --password 123456 --host 10.10.10.10 --port 27017 --authenticationDatabase admin <<EOF
use apple;
print("该实例上的连接数情况:db.serverStatus().connections;");
db.serverStatus().connections;
print("===========================");
db.currentOp({ "desc" :{\$nin: ["rsSync-0","ReplBatcher","monitoring keys for HMAC","WT OplogTruncaterThread: local.oplog.rs","NoopWriter"]}});
EOF

 

 

 

 

 

 

 

 

 

 

 

 

 

###################

posted @ 2021-01-22 17:31  igoodful  阅读(454)  评论(0编辑  收藏  举报