1、mongo提供*.js的方法供linux调用
#!/bin/bash /usr/local/mongodb/bin/mongo hostname/dbname xxx.js xxx.js 内容如下 db.getCollection('CollectinName').drop(); db.getCollection('CollectinName').insert([ { "id":"100", "name":"luyi" }, { "id":"200", "name":"wanger" } ]} ......
2、把参数传到mongo命令中:
DSID=$1 /usr/local/mongodb/bin/mongo ${hostname}/${dbname} <<-EOF db.DataTable.remove({"dsId":"$DSID"}) db.Datasource.remove({"dsId":"$DSID"}) exit EOF