将mongoexport和--query一起用于ISODate [英] Use mongoexport with a --query for ISODate

查看:461
本文介绍了将mongoexport和--query一起用于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" mongoexport.因此,指定日期"的方法是使用 $date 代替.而 --query 只是查询字符串"(JSON格式).并非整个命令都输入到外壳程序中:

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和--query一起用于ISODate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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