I'm trying to follow this tutorial to send form data to mongodb:
Save form data to MongoDB with NodeJS · programming mentor[
^]
This is how he connects to mongodb:
var dbConn = mongodb.MongoClient.connect('mongodb://localhost:27017');
This is what he does later in the code:
app.post('/post-feedback', function (req, res) {
dbConn.then(function(db) {
delete req.body._id;
db.collection('feedbacks').insertOne(req.body);
});
res.send('Data received:\n' + JSON.stringify(req.body));
});
which gives the following error:
TypeError: dbcollection is not a function
It seems that since I'm using version 3.6 of mongo, I need to connect in another way for the code to work. But how?
What I have tried:
I tried to connect like this:
var dbConn = MongoClient.connect('mongodb://localhost', function (err, client) {
if (err) throw err;
var db = client.db('mytestingdb');
});
But that just gives me another error (though in a different part of the code):
TypeError: Cannot read property then of undefined