shell操作mongodb,shellmongodb
想通过shell查询MongoDB的数据
网上好多人说,mongoDB不支持shell,这个说法我是基本赞同的
;
但是项目需要,我不得不尝试着做,关键要使用--eval
如我要查询用户数量:
#cat count_users.sh
#!/bin/sh
/usr/bin/mongo xxx --quiet --authenticationDatabase admin -u root -p 'xyz' --eval "db.system.users.count()"
注意:
1.quiet只输出结果
2.eval这是evaluate javascript
3.--authenticationDatabase admin 执行auth验证,这个不能忘记啊!
authenticationDatabase可以参看我这篇文章:http://blog.csdn.net/jacson_bai/article/details/41013259
本站文章为和通数据库网友分享或者投稿,欢迎任何形式的转载,但请务必注明出处.
同时文章内容如有侵犯了您的权益,请联系QQ:970679559,我们会在尽快处理。