0

I have a MongoDB (v 3.4.19) installed and running. After importing the data in .JSON format, one of the fields in the collection is recognised as string instead of the proper date or datetime format. I try to convert the fields, but what is my surprise after discovering that the fields with null values are filled with random (?) dates. I tried many different approaches, all of them without success. I wonder if any of you can give me a hand with this issue.

This is the code I have been using until now:

db.MIDAS_weather.find()
    .batchSize(1000)
    .forEach(function(doc) { 
        doc.METO_STMP_TIME=new Date(doc.METO_STMP_TIME);
        db.MIDAS_weather.save(doc); 
    });

After importing the JSON files, the null values are in the right place. Is only after attempting the conversion when the data is messed.

4
  • 2
    .find({ METO_STMP_TIME: { "$exists": true, "$ne": null }). Also batchSize() does not do what you think, and there are better ways to write the loop. See second link for reference. Commented Mar 7, 2019 at 22:03
  • Thanks for the answer, Neil. However, I can't find that second link that you are mentioning. Commented Mar 7, 2019 at 22:07
  • Big box above your question, including Update MongoDB field using value of another field Commented Mar 7, 2019 at 22:08
  • Oh, sorry. Thank you very much. Commented Mar 7, 2019 at 22:09

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.