无法读取属性';收集';在node.js中连接到mongodb时的未定义值?
单击中的“登录”按钮后,我正在尝试从signin.ejs文件登录 我的登录页面显示“无法读取未定义的属性集合”问题是什么 问题 我在app.js中这样定义了我的路线:无法读取属性';收集';在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
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);
}
});
},
}