将 mongoexport 与 ISODate 的 --query 一起使用 [英] Use mongoexport with a --query for ISODate
问题描述
我有这个查询,但我收到一个语法错误:意外的标识符
I have this query but i´m getting a syntax error: unexpected identifier
mongoexport --db ium --collection events
--query 'db.events.find({'created_at' : {
$gte: ISODate("2016-03-01T00:00:00.001Z"),
$lte: ISODate("2016-03-29T23:59:59:59.000Z")
},
"name" : "UPDATE_SUCCESS"})'
--out guille1_test.json
有什么问题吗?
推荐答案
您需要在查询中使用 "extended json"蒙戈出口.所以指定日期"的方法是 $date
代替.而 --query
只是 JSON 格式的查询字符串".不是整个命令输入到 shell 中:
You need to use "extended json" in queries with mongoexport. So the way to specify "dates" is with $date
instead. And the --query
is just the "query string" in JSON format. Not the whole command entered into the shell:
mongoexport --db ium --collection events
--query '{
"created_at": {
"$gte": { "$date": "2016-03-01T00:00:00.001Z" },
"$lte": { "$date": "2016-03-29T23:59:59.000Z" }
},
"name": "UPDATE_SUCCESS"
}'
--out guile1_test.json
还要注意 $lte
参数,当然还有围绕 JSON 参数主体的 ''
和围绕内部表达式和值的 ""
的引用"使用.重要,这些类型的引号是不同的,shell 参数"的外部"引号应该是 ''
,否则shell"会尝试计算包含的表达式.
Note also the corrected date string in the $lte
argument and of course the "quoting" use of ''
around the body of the JSON argument and ""
around the internal expressions and values. It s important that these types of quotes are different, as well as "shell arguments" should have their "outer" quotes as ''
, otherwise the "shell" tries to evaluate the expression contained.
这篇关于将 mongoexport 与 ISODate 的 --query 一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!