Я хочу получить данные моей коллекции, моя коллекция называется students
и является частью моей pool
базы данных.
Соединение с mongoDB работает, однако console.log(result.lastname)
возвращает undefined
.
Вот мой server.js
файл
var mongo = require('mongodb');
var assert = require('assert');
const url = 'mongodb://localhost:27017/';
mongo.connect(url, function (err, db) {
if(err) {
console.log("Connection failed");
}
console.log("Connection successfull");
var dbo = db.db("pool");
dbo.collection("students").find({}, function(err, result) {
if (err) throw err;
console.log(result.lastname);
db.close();
});
});
И содержимое моей students
коллекции, которое я вижу, используя db.students.find();
непосредственно в консоли
{ "_id" : ObjectId("5eb1570f2c0167c90cc127fd"), "id" : 0, "lastname" : "Sam", "firstname" : "Sung", "email" : "sc@mail.com", "phone" : 613295990, "validated" : "Validated", "admin" : true }