MongoDB:将mongoexport与--query选项一起使用时出现问题 [英] MongoDB: Issue when using mongoexport with --query option

查看:579
本文介绍了MongoDB:将mongoexport与--query选项一起使用时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试使用--query选项使用mongoexport进行备份以获取状态等于A的文档时,遇到以下错误:

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

错误验证设置:查询 {status:A}无效的JSON

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

请让我知道如何使用--query选项。

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

推荐答案

假设您从DOS命令提示符运行此命令,则需要交换单引号和双引号。您需要将整个查询用双引号引起来,并在JSON文档中使用单引号,如下所示:

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'}"

我已经用 mongoexport测试了它版本3.0.0和3.2.0,并且适用于两个版本。

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

这篇关于MongoDB:将mongoexport与--query选项一起使用时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆