Answer the question
In order to leave comments, you need to log in
Why does mongo connect to the db only after all query operations are done?
Hi everyone, please advise.
There is a handler functionres.end(handler);
function handler() {
function connect() {
var data = "no data";
mongo.connect(...) {...
подключение к БД и получение результата
console.log("connected")
}
}
вывод результата
console.log("result")
}
"result"
"connected"
connect
data
handler
"connected"
Answer the question
In order to leave comments, you need to log in
Because the mongo.connect() operation is asynchronous. And the event loop doesn't stop at it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question