Async Newbie Question (Stock Price Checker Project)

Hey everyone,

So I’ve been running through information security/quality assurance projects and have hit a bit of a mental block on the stock checker project.

The way I’ve been approaching it is to have one function handle fetching and returning the stock data from alphavantage.co while another checks a mongoDB collection for the ‘Likes’ data and returns it. These functions are called inside the route.get handler in an async function where the data is combined into the GET response object.

Most of this is going just dandy. Where I’m hitting a snag is in returning the ‘Likes’ data:

  this.handleLikesData = async function(stock, like, ip) {
    /* Handles the like data for a single stock entry */
    let response = {stock: stock.toUpperCase(), likes: []};
    
    if (like) {
      MongoClient.connect(CONNECTION_STRING, (err, db) => {
        if (err) return console.log(err);

        db.collection('stocks').findOneAndUpdate(
          {stock: stock.toUpperCase()},
          {$addToSet: {likes: ip}},
          {upsert: true, returnOriginal: false},
          (err, doc) => {
            if (err) return console.log(err);
            console.log('Doc: ', doc.value);
            if (doc.value) response.likes = doc.value.likes;
          });
        db.close();
      });
    }
    
    else {
      MongoClient.connect(CONNECTION_STRING, (err, db) => {
        if (err) console.log(err);
        
        db.collection('stocks')
          .find({stock: stock.toUpperCase()})
          .limit(1)
          .toArray(
              (err, doc) => {
                if (err) console.log(err);
                console.log('Doc: ', doc);
                if (doc.length != 0) response.likes = doc[0].likes;
          });
        db.close();
      });
    };
    
  };

Doubting the spoiler tag is needed, but just in case…
I guess ideally I’d have a good way of this.handleLikesData() returning response after one of the database functions modifies it. As a newcomer to the asynchronous world, I ask, what is the best way to do so? I’m also open to better suggestions to get this job done if I’m unknowingly going about this poorly.