如何在Linux Shell脚本中执行MongoDB命令

今天有同事问到了,简单的写两个应用。

方法一   shell脚本代码如下:

#! /bin/bash

./mongo 127.0.0.1:27017/test <

方法二    上面这种写法也同样可以用下面这种方式执行:

1.MongoDB脚本test.js

var cursor = db.UserInfo.find();
while(cursor.hasNext()){
  var item = cursor.next();
  print(item.userAccount);
}

2.Shell脚本

#! /bin/bash

./mongo 127.0.0.1:27017/test ./test.js

 

你可能感兴趣的:(数据库)