Mongoexport错误解析查询 [英] Mongoexport error parsing query
问题描述
我正在尝试对CSV进行mongoexport,但仅通过查询选择某些记录.这是我的命令(Windows 7 cmd):
Im trying to do a mongoexport to CSV but only selecting certain records with a query. Here's my command (windows 7 cmd):
mongoexport --host foo.com --port 27017 --username bar -p --db foo --csv --fields col1,col2,col3 --collection bar --out dump_q.csv --query '{"recent":"yes"}'
但是输入密码后,我得到一个错误:
However after entering the password, I get an error:
assertion: 16619 code FailedToParse: FailedToParse: Expecting '{': offset:0
该命令在没有查询参数的情况下仍能正常工作,但我无法弄清楚查询出了什么问题:
The command works fine without the query argument but I cant figure out whats wrong with the query:
--query '{"recent":"yes"}'
非常感谢任何帮助
-
确保在查询中使用双引号,而在字符串中使用单引号
Make sure you use double quotes on enclose the query and single quotes to enclose strings e.g.
-查询"{{recent':'yes'}"
--query "{'recent':'yes'}"
还要确保查询中没有空格,否则命令提示符会将其解析为另一个参数.因此,没有:
Also make sure you don't have a space in your query otherwise the command prompt will parse it as another argument. So don't have:
-查询"{'recent':'yes'}" (注意它们之间的空间)
--query "{'recent': 'yes'}" (notice the space in-between)
包含嵌套字段的查询无法正常工作,例如:
Queries which include nested fields don't work such as:
-查询"{'folder.recent':'yes'}"
--query "{'folder.recent':'yes'}"
推荐答案
您将需要使用双引号来包含查询字符串(并且单引号或两个引号可以在字符串内转义)
You'll need to use double quotes to contain the query string (and either single quotes or two quotes to escape inside of the string)
--query "{'recent':'yes'}"
完成:
mongoexport --host foo.com --port 27017 --username bar -p
--db foo --csv --fields col1,col2,col3
--collection bar --out dump_q.csv --query "{'recent':'yes'}"
这篇关于Mongoexport错误解析查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!