The following code runs fine. data gets inserted into the collection. However, the program doesnoot exit. The console just stays there. How to exit gracefully?
const mongoClient = require('mongodb').MongoClient
const url = 'mongodb://localhost:27017'
const schema = 'learndb'
const client = new mongoClient(url,{ useUnifiedTopology: true })
const connection = client.connect(function(err,client){
if(err){
console.log('~~~UNABLE TO CONNECT TO MONGO~~~')
throw err
}
console.log('~~~SUCCESSFULLY CONNECTED TO MONGO~~~')
})
const db = client.db(schema)
db.collection('mycol').insertMany ([
{id:'1101',value:'ddddddddd'},
{id:'1102',value:'aaaaaaaaa'},
{id:'1103',value:'bbbbbbbbb'},
{id:'1104',value:'ccccccccc'},
])