MongoDB: Issue when using mongoexport with --query option

懵懂的女人 提交于 2020-03-21 04:52:30

问题


When I try to take backup with mongoexport using the --query option to get the documents whose status is equal to A, facing the below error:

mongoexport --port 27017 --db ex --collection A --type=csv --fields _id,status --query '{"status":"A"}' -o eg.csv

error validating settings: query ''{status:A}'' is not valid JSON

Please let me know how to use --query option.


回答1:


Assuming you run this from the DOS command prompt, you need to swap the single and double quotes. You need to wrap the entire query in double quotes and use single quotes inside the JSON document like this:

--query "{'status':'A'}"

I have tested this with mongoexport version 3.0.0 and 3.2.0 and it works for both versions.



来源:https://stackoverflow.com/questions/34393757/mongodb-issue-when-using-mongoexport-with-query-option

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!