Answer the question
In order to leave comments, you need to log in
How to get data from a collection?
Hi everyone
, I'm facing the same problem. I can't display data from mongodb.
Everything works in the console, but when I connect, I can only add data, but I can’t display it, it writes an error.
TypeError: Cannot read property 'find' of undefined
at \NodeTemplate\server.js:28:25
at \NodeTemplate\node_modules\mongodb\lib\mongo_client.js:210:11
at nextTickCallbackWith0Args (node.js:420:9)
at process._tickCallback (node.js:349:13)
MongoClient.connect("mongodb://localhost:27017/nodedb", function(err, db) {
if(!err) {
console.log("We are connected");
}
console.log(db.users.find({"name":"Alex"}));
});
MongoClient.connect("mongodb://localhost:27017/nodedb", function(err, db) {
if(!err) {
console.log("We are connected");
}
var user = {_id:2,name:"Alex",password:"123456"};
collection.insert(user);
});
//'этот скрипт работает. он добавляет данные в колекцию
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