通过shell脚本对MongoDB进行自动化操作
运行写好的 ./show.sh 脚本 发现能够建立mongo链接,但是第二条开始就无法运行了
脚本内容如下
#!/bin/sh mongo WordPress show collections db.posts.find().limit(10)
不知道是什么原因呢?
认证0级讲师
Starting from the second item is the mongo shell statement, which of course cannot be run.
It should be like this:
#!/bin/sh mongo WordPress --eval "show collections;db.posts.find().limit(10);"
Or use mongo as a shell parser:
#!/usr/bin/env mongo WordPress show collections db.posts.find().limit(10)
- -# To write js, use ./mongo /path/to/test.js
Starting from the second item is the mongo shell statement, which of course cannot be run.
It should be like this:
Or use mongo as a shell parser:
- -# To write js, use ./mongo /path/to/test.js