M
M
miliko mikoyan2018-11-15 02:23:29
MongoDB
miliko mikoyan, 2018-11-15 02:23:29

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

1 answer(s)
S
shai_hulud, 2018-11-15
@shai_hulud

Maybe
or even
db.collection.users;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question