Bash 使用shell脚本进行Mongoexport和查询
我正在使用shell脚本调用mongoexport,但一直失败。我的剧本是:—— 但每次运行时,它都会失败,并出现以下错误:-- 现在我不确定我到底在哪里弄乱了语法Bash 使用shell脚本进行Mongoexport和查询,bash,mongodb,Bash,Mongodb,我正在使用shell脚本调用mongoexport,但一直失败。我的剧本是:—— 但每次运行时,它都会失败,并出现以下错误:-- 现在我不确定我到底在哪里弄乱了语法 问候。您似乎正在连接到您的mongo。执行mongoexport不需要这样做。 您只需要连接到主机(而不是mongo)。看一看 此数据驻留在主机上的MongoDB实例上 在端口37017上运行的mongodb1.example.net,需要 用户名用户和密码通行证 mongoexport--主机mongodb1.example.ne
问候。您似乎正在连接到您的mongo。执行
mongoexport
不需要这样做。
您只需要连接到主机(而不是mongo)。看一看
此数据驻留在主机上的MongoDB实例上
在端口37017上运行的mongodb1.example.net,需要
用户名用户和密码通行证
mongoexport--主机mongodb1.example.net--端口37017--用户名用户
--密码“pass”--集合联系人--db marketing--out mdb1-examplenet.json
在您的情况下,它应该是这样的(未经测试)
我假设您的数据库名为admin,而您的集合名为db1,如果没有相应地替换它们的话
mongo localhost:27038/admin -u test -p mongo123 < mongoexport.js
use db1
mongoexport --type=csv --fields _id -q '{"_id": "323549991" , "cat" : "ABC"}' --out report.csv
switched to db db1
2018-01-10T17:36:15.495+0000 E QUERY [thread1] SyntaxError: missing ; before statement @(shell):1:14
bye
mongoexport --host localhost --port 27038 --username test --password "mongo123" --db admin --collection db1 --type=csv --fields _id -q '{"_id": "323549991" , "cat" : "ABC"}' --out report.csv