Convert every date to epoch timestamp text/JSON

I'm receiving some JSON files through a git repo I need to feed into a database.

Is there any command line script/utility so I can convert every date in the json fields from ISO 8601 (example: 2014-11-18T23:00:00.000Z) to its timestamp/unix epoch equivalent?

Upvotes: 0

Views: 340

Answers (1)

marijnz0r
marijnz0r

Reputation: 934

This is what I used to go from timestamp to ISODate, hope you find this helpful to get what you want.

/usr/bin/mongo mydb --eval 
"db.collection.find().forEach(function(doc){
doc.timestamp = new ISODate(new Date(doc.timestamp).toISOString());
db.collection.save(doc)
});"

Also, use this. Good luck!

Upvotes: 2

Related Questions