[英]Mongoexport error parsing query
Im trying to do a mongoexport to CSV but only selecting certain records with a query. 我正在尝试将mongoexport导出为CSV,但只能通过查询选择某些记录。 Here's my command (windows 7 cmd):
这是我的命令(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"}'
Any help much appreciated 任何帮助,不胜感激
Make sure you use double quotes on enclose the query and single quotes to enclose strings eg 确保使用双引号将查询括起来,并使用单引号将字符串括起来,例如
--query "{'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 :
所以没有 :
--query "{'recent': 'yes'}" (notice the space in-between) --query“ {'recent':'yes'}”(注意中间的空格)
Queries which include nested fields don't work such as: 包含嵌套字段的查询无法正常工作,例如:
--query "{'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'}"
Complete: 完成:
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'}"
From mongoexport documentation : 从mongoexport文档中 :
--query , -q
--query,-q
Provides a JSON document as a query that optionally limits the documents returned in the export.
Your query string seems to be correctly formated. 您的查询字符串似乎格式正确。 You can even ommit the double quotes around recent .
您甚至可以省略最近的双引号。
Single or double quotes don't seem to matter, as long as you are persistent in using different types on the outside and the inside. 只要您坚持在外部和内部使用不同的类型,单引号或双引号似乎无关紧要。
Are you sure this is a valid query though? 您确定这是有效查询吗? What is the output if you run the following in the database?
如果在数据库中运行以下命令,输出是什么? What about a find() ?
那find()呢?
db.bar.count({"recent":"yes"})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.