Chapter 10: Optimize Async samples

This commit is contained in:
Beth Griggs
2020-08-31 01:24:43 +01:00
parent 52d632f0d2
commit 2e8f3240ec
6 changed files with 605 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
const MongoClient = require("mongodb").MongoClient;
const URL = "mongodb://localhost:27017/";
let values = [];
const numberOfValues = 1000;
let count = 0;
for (count; count < numberOfValues; count++) {
values.push({ value: Math.round(Math.random() * 100000) });
}
MongoClient.connect(URL, { useUnifiedTopology: true }, (err, client) => {
if (err) throw err;
const db = client.db("data");
db.collection("values").insertMany(values, (err) => {
if (err) throw err;
console.log(`Added ${numberOfValues} random values.`);
client.close();
});
});