Click here to Skip to main content
15,887,822 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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; // for safety reasons
        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
Posted
Updated 30-Jul-18 4:04am

1 solution

This problem is due to mongodb version , uninstall the existing mongodb
`npm uninstall mongodb` and install ` npm install mongodb@2.2.33 --save`
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900