Answer the question
In order to leave comments, you need to log in
MongoDB and NodeJs?
for some reason, the function writes undefined to me, maybe the function did it wrong, but did it?
function checkUserIdentity(lg) {
MongoClient.connect('mongodb://адрес', function (err, db) {
if (err)
throw err;
var collection = db
.collection('client')
.findOne({
login : lg
}, function (err, docs) {
if (docs) {
return docs._id;
}else {
return "not exist";
}
})
});
}
MongoClient.connect('mongodb://адрес', function (err, db) {
if (err)
throw err;
var collection = db
.collection('client')
.findOne({
login : lg
}, function (err, docs) {
if (docs) {
return docs._id;
}else {
return "not exist";
}
})
});
Answer the question
In order to leave comments, you need to log in
function checkUserIdentity(lg, callback) {
MongoClient.connect('mongodb://адрес', function (err, db) {
if (err) throw err;
db.collection('client').findOne({ login : lg }, function (err, docs) {
if (docs) callback(null, docs._id);
else callback(new Error("not exists"));
});
});
}
when i do console.log(checkUserIdentity("")) // response is undefined
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question