I tried to create 5 documents in mondoDB , and I’m sure that I successfully created 5 documents.
But it only shows one document on Robo3T.
Here is my code
const Category = require('../category')
const db = require('../../config/mongoose')
const categoryList = require('./categoryList.json')
db.once('open', () => {
return Promise.all(Array.from({ length: 5 }, (_, index) => {
Category.create({
name: categoryList[index].name,
icon: categoryList[index].icon
})
}))
.then(() => console.log('categorySeeder.js is done'))
.then(() => process.exit())
})
And here is my Robo3T
enter image description here
2
Answers
Try this
Use aysnc/await