Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法读取属性';收集';在node.js中连接到mongodb时的未定义值?_Node.js_Mongodb - Fatal编程技术网

无法读取属性';收集';在node.js中连接到mongodb时的未定义值?

无法读取属性';收集';在node.js中连接到mongodb时的未定义值?,node.js,mongodb,Node.js,Mongodb,单击中的“登录”按钮后,我正在尝试从signin.ejs文件登录 我的登录页面显示“无法读取未定义的属性集合”问题是什么 问题 我在app.js中这样定义了我的路线: app.post('/login', routes.dologin); 我在index.js中定义了我的多洛金路线: exports.dologin = function (req, res) { res.locals.session = req.session; var user = req.body.user; db.au

单击中的“登录”按钮后,我正在尝试从signin.ejs文件登录 我的登录页面显示“无法读取未定义的属性集合”问题是什么 问题

我在app.js中这样定义了我的路线:

app.post('/login', routes.dologin);
我在index.js中定义了我的多洛金路线:

exports.dologin = function (req, res) {
res.locals.session = req.session;

var user = req.body.user;
db.authenticateUser(user.email, user.password, function     ( err, response) {
if (err) {
.......

.......
} else {
.......

........  
}
});
};
在my db.js中:

var mongo = require('mongoskin'),
crypto = require('crypto');

module.exports = function (config) {

var USERS_COLLECTION = 'users',
ORDERS_COLLECTION = 'orders',
salt = 'supersecretkey',
db;

    authenticateUser: function (emailId, password,         callback) {
    db.collection(USERS_COLLECTION).count({email : emailId,         password: encryptPassword(password)}, function (err,         count) {
    if (err) {
console.log("error authenticating user: " + err);
callback(new Error(err));
} else if (count === 0) {
callback(new Error("emailid/password did not match"));
} else {
callback(null);
}
});
},
    }
获取“集合未定义”的问题是什么?我想在这里
一切都是对的。。。这里有什么问题吗?告诉我……谢谢

您应该添加此代码
db=mongo.db('localhost:27017/yourdb')


您应该添加以下代码
db=mongo.db('localhost:27017/yourdb')


db
未定义,
var db
不是有效的db对象
db
未定义,
var db
不是有效的db对象,但我在return语句中添加了如下内容:return{configure:function(config){db=mongo.db((config?config:'mongodb://localhost:27017/paypal),{w:1};}但我在return语句中添加了如下内容:return{configure:function(config){db=mongo.db((config?config:'mongodb://localhost:27017/paypal),{w:1};}
var mongo = require('mongoskin'),
    crypto = require('crypto');

module.exports = function (config) {

    var USERS_COLLECTION = 'users',
        ORDERS_COLLECTION = 'orders',
        salt = 'supersecretkey',
        db = mongo.db('localhost:27017/yourdb');

    authenticateUser: function (emailId, password, callback) {

        db.collection(USERS_COLLECTION).count({
            email: emailId,
            password: encryptPassword(password)
        }, function (err, count) {
            if (err) {
                console.log("error authenticating user: " + err);
                callback(new Error(err));
            } else if (count === 0) {
                callback(new Error("emailid/password did not match"));
            } else {
                callback(null);
            }
        });
    },
}