async function a(){
await note.save().then(()=>{
console.log('Phonebook:')
})
await Person.find({}).then(people=>{
people.forEach(person=>{
console.log(person.name,person.number)
})
})
mongoose.connection.close()
}
a()
The above code snippet executes without problems.But if I put mongoose.connection.close() behind the forEachfunction
async function a(){
await note.save().then(()=>{
console.log('Phonebook:')
})
await Person.find({}).then(people=>{
people.forEach(person=>{
console.log(person.name,person.number)
})
mongoose.connection.close()
})
}
a()
the process doesn’t end. Why?