Answer the question
In order to leave comments, you need to log in
TypeError: db.collection is not a function?
var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://localhost:27017/userCollectionDB";
MongoClient.connect(url, function(err, db){
var collection = db.collection('users');
var user = {firstName : "Ivan", lastName : "Ivanov", age: 30};
collection.insertOne(user, function(err, result){
if(err){
console.log('sssss');
return;
}
console.log(result.ops);
db.close();
});
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question