I want to use an express way to post numerous objects to my Mongo database. As you can see below, everything is now operating smoothly when I do it as a single object (i.e., ONE casino). However, rather than repeating this process a million times, can someone kindly assist me in doing it as a massive data dump so I may upload ALL of my casinos?
Here is my method, which is suitable for submitting a single item:
router.post('/post', async (req, res) => {
console.log(req.body);
const casinoD = new Casino({
casino: req.body.casino,
table_and_other: req.body.table_and_other,
poker: req.body.poker,
slot_machines: req.body.slot_machines,
total_gaming_win: req.body.total_gaming_win,
year: req.body.year,
month: req.body.month,
combined_date: req.body.combined_date
})
try {
const newCasino = await casinoD.save()
res.status(201).json(newCasino)
} catch (err) {
res.status(400).json({ message: err.message})
}
})
I also realize that using mongoimport is a better option, however that method has its own problems.
Thanks