I need to export the data from a Dev MongoDB collection and deploy the data into another environment(UAT) collection. I was using MongoDB compass Export Collection tool to output the documents as Json format and then import the Json file using the GUI add data tool, it was working fine without a problem.
I will need to script everything so it can be run from command line instead of manually using the tool then I noticed that the json format generated from the Export Collection tool has changed some data type. When I use insertMany command to insert the output Json file. It will have errors. For example, I have some date field, the output generated from Export Collection tool converted them to
"$date": {
"$numberLong": "1650603600000"
}
Instead, it should be format like ISODate("2022-06-02T05:00:00.000Z").
It wasn’t causing issue using the GUI to add the data using this format but if I use the command insertMany and then insert the Json format, the data will not be date anymore. Any way to get around this problem?
2
Answers
You need to change your date:
From this:
To this:
Please download MongoDB Shell and run it on the terminal (not on MongoDB Compass), and you will get it.