These are chat archives for Automattic/mongoose

Dec 2018
Paul "Joey" Clark
Dec 26 2018 04:03
@bhasin11 You can’t do that. If you put console.log there, it will always run immediately, before the DB query has time to respond!
You need to put your console.log() and any work you want to do with the results, inside the callback function.
(I also recommend using promises instead of callback functions. That saves you from writing so much error-handing code.)

@rdy23x @bhasin11 You can’t do

const result = model.find(…);

because it takes time for the query to happen, and sychronous Javascript doesn’t wait.
But you can do

const result = await model.find(…);