I am trying to post data to database that I have created on mLab and I am getting this error but I don\'t know whats going wrong.I also have read previously asked question o
Dont use database name in connection url:
const mongo_url = 'mongodb://localhost:27017'
Instead use below method:
MongoClient.connect(mongo_url , { useNewUrlParser: true }, (err, client) => {
if (err) return console.log(err)
const db = client.db('student')
const collection = db.collection('test_student');
console.log(req.body);
collection.insertOne(req.body,(err,result)=>{
if(err){
res.json(err);
}
res.json(result);
});
});