I have the following code that finds any documents missing DateUTC and loop through and set the date using a datestring value contained in the document. The data is imported via JSON files so dates need to be cast to UTC date. However i am getting 'Process Out of Memory' when there are >1000 records. The documents are quite large JSON weather readings. I am new to MongoDb and Node but this is not a lot of data to update so I figure i am doing something wrong.
'use strict';
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var db = mongoose.connection;
var Grib = require('./models/grib.js');
var fs = require('fs');
var moment = require('moment');
//register call back events
db.on('error', console.error);
db.once('open', function () {
//do our DB work here
var today = moment().startOf('day');
var tomorrow = moment(today).add(1, 'day');
var yesterday = moment(today).add(-1, 'day');
Grib.find({ 'header.dateUTC': null }, {}, {}, function (err, array) {
for (var i = 0, len = array.length; i < len; i++) {
array[i].header.dateUTC = moment.utc(array[i].header.refTime).toDate();
array[i].save(function (err) {
if (err) console.log('save error:' + err);
});
};
console.log('Number of grib dates updated:' + array.length);
});