I have a requirement to store multiple objects in my mongo database within an express route. Currently, the process is smooth when I post individual objects (such as ONE casino), as shown below. Instead of repeating this numerous times, I am seeking assistance to do it as a single data dump so I can upload ALL my casinos at once.
Below is the functioning route for posting a single object:
router.post('/post', async (req, res) => {
console.log(req.body);
const casinoData = 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 casinoData.save()
res.status(201).json(newCasino)
} catch (err) {
res.status(400).json({ message: err.message})
}
})
I am aware that using mongoimport could be a more efficient way to handle this, but it also comes with its own set of challenges.
Thank you