mongodb脚本执行

1.编写脚本:job.js,内容如下:

conn = new Mongo("mongodb://abc:b=abc@10.0.1.183:27017,10.0.1.184:27017/wps_credit?maxPoolSize=300&replicaSet=c45134ec-6a5f-461e-8745-7081b46b0d87");
db = conn.getDB("abc");
 
var result = db.transaction_5.find().limit(10);
while(result.hasNext()) {
    printjson(result.next());
}
var tm = new Date();
printjson(db.transaction_6.count());
db.transaction_6.remove({});
printjson(db.transaction_7.count());
db.transaction_7.remove({});
printjson(db.transaction_8.count());
db.transaction_8.remove({});
 
var t2 = new Date().getTime() - t1;
printjson(t2);

2.执行它

mongo -nodb job.js