I have a project im working on and I have to seed a database with 10 million random rows, which i have successfully done. However it takes about 30 minutes for it to complete, which is expected, but i know it could be faster. I would like to make it run ever faster and figure out a way to make it seed 10 million random entries in under 10 minutes preferably while still using mongodb/mongoose. This is my current seed file, any tips on making it run faster? First time posting on here, just fyi. thanks!
I use 'node database/seed.js' to run this file in the terminal.
const db = require("./index.js");
const mongoose = require("mongoose");
const faker = require("faker");
const productSchema = mongoose.Schema({
product_name: String,
image: String,
price: String
});
let Product = mongoose.model("Product", productSchema);
async function seed() {
for (let i = 0; i < 10000000; i++) {
let name = faker.commerce.productName();
let image = faker.image.imageUrl();
let price = faker.commerce.price();
let item = new Product({
product_name: `${name}`,
image: `${image}`,
price: `$${price}`
});
await item
.save()
.then(success => {})
.catch(err => {});
}
}
seed();