How comes one can console.log data from a document in mongoDB/mongoose, but that data can not be saved to a variable?

Hi there!

How comes one can console.log data from a document in mongoDB/mongoose, but that data can not be saved to a variable?

Or maybe I am doing it totally wrong?
I can res.json the document data as well, so it seems like I should be able to do common javascript actions with that information

Thank you so much!

You’ll need to handle asynchronous operations in Mongoose appropriately. The documentation at Mongoose Docs will help you with this.
https://mongoosejs.com/docs/promises.html

1 Like