function pad(n) { return n < 10 ? '0' + n : n }; function ISODateString(d) { return d.getUTCFullYear() + '-' + pad(d.getUTCMonth() + 1) +'-' + pad(d.getUTCDate()) + 'T' + pad(d.getUTCHours()) + ':' + pad(d.getUTCMinutes()) + ':' + pad(d.getUTCSeconds()); }; print("Starting fill database: " + Date()); maxLines = 1000; progressStep = maxLines / 100; devicesCount = maxLines / 5; for (var i = 1; i <= maxLines; i++) { db.measuresData.insert( { "measureId" : i, "deviceId" : Math.floor(Math.random() * devicesCount + 1), "stateId" : Math.floor(Math.random() * 2 + 1), "groupId" : Math.floor(Math.random() * 100 + 1), "measureDate": new Date(), "intVal" : Math.floor(Math.random() * 2000000 - 1000000), "floatVal" : Math.random() * 2000000 - 1000000 }); if (i % progressStep == 0) { print(i + ";" + ISODateString(new Date())); } }; print("Finished at: " + Date());