use shell command
method one:
#!/bin/bash if [ $# -ne 1 ] then echo 'Please input cid' exit fi HOST=192.168.1.1:27017 mongo ${HOST}/new_db << EOF db.camp.findOne({"cId":$1}); EOF
method two:
echo"db.mycollection.findOne()" | mongo myDbName echo"show collections" | mongo myDbName
refer:http://ask.helplib.com/281277
refer: http://www.epubit.com.cn/book/onlinechapter/27994