如何使用人类可读的日期格式将BSON转换为JSON [英] How to convert BSON to JSON with human-readable date format
问题描述
我想将MongoDB的BSON转储转换为JSON.
I would like to transform a BSON dump of MongoDB to JSON.
为此,我使用了随提供的 bsondump 工具Mongo,但是我得到的输出是:
To do that, I'm using the bsondump tool provided with Mongo, but I get an output like :
{ "_id" : ObjectId( "5316d194b34f6a0c8776e187" ), "begin_date" : Date( 1394004372038 ), "foo" : "bar" }
{ "_id" : ObjectId( "5316d198b34f6a0c8776e188" ), "begin_date" : Date( 1394004407696 ), "foo" : "bar" }
谁能告诉我日期如何以人类可读的格式显示(例如hh:mm:ss dd/mm/yyyy
)?
Can anyone tell me how to get the dates appear in a human readable format (e.g. hh:mm:ss dd/mm/yyyy
) ?
修改
似乎最新版本的mongodump输出日期为:
It looks like that a more recent version of mongodump outputs dates as:
{ "_id" : ObjectId( "5316d194b34f6a0c8776e187" ), "begin_date" : {"$date":"2015-11-11T08:45:03.974Z"}}, "foo" : "bar" }
所以这个问题不再重要了. 谢谢大家在这里的帮助.
So this question is not relevant anymore. Thanks everybody for your help here.
推荐答案
bsondump将BSON文件转换为人类可读的格式, 包括JSON.例如,bsondump可用于读取输出 mongodump生成的文件.
bsondump converts BSON files into human-readable formats, including JSON. For example, bsondump is useful for reading the output files generated by mongodump.
来源: https://docs.mongodb.com/manual/reference/program/bsondump
示例
bsondump --outFile collection.json collection.bson
--pretty
选项以漂亮的打印格式JSON输出文档,例如:
The --pretty
option outputs documents in a pretty-printed format JSON, eg:
bsondump --pretty --outFile collection.json collection.bson
这篇关于如何使用人类可读的日期格式将BSON转换为JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!