Ask a mongoose operation database callback function problem

  mongodb, question
var data (err, doc) {
 if (err) {
 } else {
 Log (doc)//successfully output the document object of the operation
 data = doc  //undefined
 console.log(data)   //undefined

Due to asynchrony, data cannot get the value of doc. Now it needs return data. How can I change the code?

I can think of two ways:

  1. Continue executing the code you want to execute in the callback
  2. Useasync / awaitWait for asynchronous execution to complete