0
私は、自分のメールでデータベース内のユーザーを検索する次の方法を書いています。node.jsでmongooseを使用してデータベースにクエリを行う方法
/**
* Find a user by providing their email address
*/
DataProvider.prototype.findUserByEmail = function(callback, email) {
console.log("in findUserByEmail");
User.findOne({
emailAddress : email
}, function(error, user) {
if(error) {
console.log(error);
callback(error);
}
else {
console.log(user);
callback(user);
}
});
};
私は次のようにそれをテストしようとしている:
function testFindUserByEmail() {
var expectedEmail = "[email protected]";
data.findUserByEmail(function(user) {
if (user.emailAddress === expectedEmail) {
console.log("User found");
} else {
console.log("User not found");
}
console.log(user);
}, "[email protected]");
console.log("test");
}
私はのoutout取得:findUserByEmail テストで を
それは(User.findOneようなものだが)されていません私はなぜか分からない。 その他の情報:データベース、 試し
var UserSchema = new Schema({
emailAddress : {
type : String
},
occupation : {
type : String
},
token : {
type : String
},
password : {
type : String
},
registrationDate : {
type : Date
},
activated : {
type : Boolean
}
});
/**
* Define Model
*/
var User = mongoose.model('User', UserSchema);
DataProvider = function() {
};
うんを、私が持っていました。私は問題を解決しました。 mongoDb接続に問題があったことが判明しました。私は「エラー:サーバ127.0.0.1シェル/ mongo.jsに接続できませんでした:84」というエラーが発生しました。あなたの答えをありがとう - それは私の接続をチェックする正しい方向になった – jokham