使用MongoExport,如何控制Date字段的输出? [英] Using MongoExport, how do I control the output of Date fields?
问题描述
我正在尝试将Mongo中的一些数据格式化为CSV。其中一个字段存储为ISODATE,因此在查询Mongo时,出现如下:
I am trying to format some data from Mongo into a CSV. One of the fields is stored as an ISODate, so when querying Mongo, comes out like this:
... ISODate("2011-11-19T00:23:38.786Z") ...
我有一个像以下:
C:\Mongo\bin\mongoexport --csv -f "DOB","Name","Email" -c People -d PeopleDataStore -h [hostname]
这个MongoExport命令生成类似以下:
This MongoExport command produces something like the following:
{ "$date" : 1321579509347 },"Bob","test@test.com"
如何获取MongoExport输出的日期像2011-11-19T00:23: 38.786Z,即不是一个整数表示,而不是包含在代码结构中?
How can I get the date that is the output of MongoExport to come out like "2011-11-19T00:23:38.786Z", i.e. not an integer representation, and not wrapped in code structures?
请注意,我正在尝试从命令行执行所有这些操作,而不是从可以处理结果的应用程序。应用程序将是我的回退计划。
Note that I am attempting to do all this from the command line, not from within an application that could process the results. An application will be my fallback plan.
推荐答案
不要以为只有 mongoexport
,您需要编写自己的一些导出脚本或后处理从整数(从1970年1月1日以来的毫秒)转换为ISO字符串格式的日期值。
Don't think this is possible using just mongoexport
on it own, you'll need to write your own little export script or post-process the date values to convert from the integer (milliseconds since 1 January 1970) to the ISO string format.
这篇关于使用MongoExport,如何控制Date字段的输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!