2

I have a huge JSON file (about 5 GB) with several fields in all rows. this is what one document looks like:

{ 
 "_id" : ObjectId("55f0105346c5110dfc6b8760"), 
 "patient" : "198", 
 "concept" : "Ampicillin", 
 "confidence" : NumberInt(100), 
 "value" : 1.0, 
 "time" : ISODate("2007-06-27T17:24:00.000+0000"), 
 "stay" : "20220"
}

This is data from hospital stays. For some reason, when I imported the JSON file to MongoDB (using mongoimport in linux command line), the 'time' field was saved not as ISO-date, but as a string. I figured - "no problem" and using mongo-chef altered the field to be of "Date" type using the 'Edit Value' option. I then picked the override option for all documents matching criteria.

screencap of mongochef

What happened then is that the entire collection got the exact same value in the "time" column.

So my question is - either - (A) how can I import it correctly, where mongoimport inserts the "time" as ISOdate, OR, (B) how can I correctly change it in mongochef, after the import. This is time sensitive so PLEASE if anyone has any idea - help!

Thanks!

asked Jul 6, 2016 at 11:28
1
  • It is a bit odd that mongoimport did't handle this correctly. what you can do is update strings to dataTime using forEach loop Commented Jul 6, 2016 at 16:32

1 Answer 1

4

All right. After digging a LOT I found the correct formatting is:

time: {$date:"2013-11-20T23:32:18Z"}

So I used 'sed' to change it throughout the json file and imported it.

I'm leaving this answer for the benefit of anyone who might come across this problem.

answered Jul 7, 2016 at 7:23
2
  • 1
    For MongoChef you have to add the millisecond part: 2016年03月07日T20:03:46.157Z Commented Sep 22, 2016 at 10:23
  • Is mandatory use "$date", so "" are mandatory. It is imported later how a ISODate("same pattern used") type Commented Apr 15, 2021 at 23:06

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.