title: Resolve promise inside chain
body: <p>I'm having some trouble resolving promises inside a chain. In the JSBin below you can see the code I have (NodeJS and mongo). How can I return the data from 2 levels down the chain? Here is the code and JSBIN</p>
  
  <pre><code>function test(url) {
    return new Promise((resolve, reject) =&gt; {
    return scrapeIt({
      url: url,
      headers: { 'User-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36' }
    }, {
        urls: {
          listItem: '#list',
          data: {
            url: {
              selector: "span[data-label='url']"
            }
          }
        },
        currentPage: {
          selector: 'span.current',
          convert: x =&gt; parseInt(x)
        },
        pages: {
          selector: 'span.pages',
          convert: x =&gt; parseInt(x)
        }
      }).then(({ data, response }) =&gt; {
        return MongoClient.connect(config.db.serverUrl, function (err, db) {
          var dbo = db.db(config.db.name)
          var urlsToInsert = data.urls
  
          return dbo.collection(config.db.collection).find({ 'url': { '$in': data.urls } }, { projection: { _id: 0 } }).toArray(function (err, res) {
            if (res &amp;&amp; res.length &gt; 0) {
              // Exclude properties already in DB
              urlsToInsert = urlsToInsert.filter(x =&gt; !res.some(y =&gt; x.url == y.url))
              if (urlsToInsert &amp;&amp; urlsToInsert.length &gt; 0)
                return dbo.collection(config.db.collection).insertMany(urlsToInsert, function (err, res) {
                  console.log("Number of documents inserted: " + res.insertedCount)
  
                  db.close()
                  return urlsToInsert
                })
            }
          })
        })
      })
  })
  }
  
  test('https://www.google.com').then(({ data, response }) =&gt; {
    console.log(data)
  }).catch((error) =&gt; {
    console.log(error)
  })
  </code></pre>
  
  <p><a href="https://jsbin.com/cejuruxofu/edit?js" rel="nofollow noreferrer">JSBin snippet</a></p>
  
  <h1>Update 1</h1>
  
  <p>My actual code is much longer so I took out a lot of the code that was not required for the issue to make sense. I fixed the issue with the urlsToInsert being null. Also returning now urlsToInsert.</p>