json - 如何将 BSON 转换为具有人类可读日期格式的 JSON

标签 json mongodb date bson

我想将 MongoDB 的 BSON 转储转换为 JSON。

为此,我使用了 bsondump Mongo 提供的工具,但我得到如下输出:

{ "_id" : ObjectId( "5316d194b34f6a0c8776e187" ), "begin_date" : Date( 1394004372038 ), "foo" : "bar" }
{ "_id" : ObjectId( "5316d198b34f6a0c8776e188" ), "begin_date" : Date( 1394004407696 ), "foo" : "bar" }

谁能告诉我如何让日期以人类可读的格式显示(例如 hh:mm:ss dd/mm/yyyy)?

编辑

看起来更新版本的 mongodump 输出日期为:

{ "_id" : ObjectId( "5316d194b34f6a0c8776e187" ), "begin_date" : {"$date":"2015-11-11T08:45:03.974Z"}}, "foo" : "bar" }

所以这个问题不再相关了。 在此感谢大家的帮助。

最佳答案

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 格式输出文档,例如:

bsondump --pretty --outFile collection.json collection.bson

关于json - 如何将 BSON 转换为具有人类可读日期格式的 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23010566/

相关文章:

java - Json 文件返回多个值,我希望我的 getter 和 setter 在设置为第一个值后拒绝其他值

Python dict 通过 json.loads : 到 JSON

c# - 未知的鉴别器值 C# Mongo

jquery - 如何在 <span> 中按内容日期对 div 进行排序

java - 如何获取文件 io 的兼容时间戳?

iphone - 将 JSON 数据从 NSData 转换为 NSDictionary

json - 尝试实现 amp-mustache 时出错

javascript - 将我的应用程序从 ruby​​/rails 重写为 javascript/express。 mongodb 能满足我的需求吗?

c# - 无效操作异常 : Record reader index out of sync

上个月的python日期