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.

Jumy Elerossë
  • 189
  • 2
  • 3
  • 12
  • 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. – Neil Lunn Mar 07 '19 at 22:03
  • Thanks for the answer, Neil. However, I can't find that second link that you are mentioning. – Jumy Elerossë Mar 07 '19 at 22:07
  • Big box above your question, including [Update MongoDB field using value of another field](https://stackoverflow.com/questions/3974985/update-mongodb-field-using-value-of-another-field) – Neil Lunn Mar 07 '19 at 22:08
  • Oh, sorry. Thank you very much. – Jumy Elerossë Mar 07 '19 at 22:09

0 Answers0