Answer the question
In order to leave comments, you need to log in
Write result from mongodb query to variable?
How to write result from mongodb query to variable.
var user = db.collection( config.db.collections.user ).findOne({ 'email' : email }, function(error, user) {
if (error) throw error;
client.close();
});
Answer the question
In order to leave comments, you need to log in
Good day!
Judging by the question and the provided code, you have no understanding of how asynchronous functions work in a node. In this answer , I already gave guidance on understanding asynchrony.
Now regarding the question.
If the code is written correctly, then the result is already stored in a variable, in this case, in the user
PS variable.
If you don't like callbacks, then use the ESNext goodies. mongodb native driver v3.0 ECMAScript Next CRUD
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question