res.render ONLY after multiple data queries have finished
<p>On my app.get in my server.js, I am returning a data set from mongo db, and then rendering my page whilst passing the data to it. </p>

<p><strong>as shown bellow:</strong></p>

<pre><code>//page load
app.get('/', (req, res) =&gt; {

    //find all data in test table
    var articles;
    db.collection('test').find().toArray((err, result) =&gt; {
        if (err) return console.log(err)
        articles = result

            // renders index.ejs and passes result to quotes
        res.render('./pages/index.ejs', {
            quotes: articles
        })
    })
})
</code></pre>

<p>I want to be able to put multiple db queries, and then pass multiple variables of data to my render, my problem is that when I put my res.render outside of a db query, it tries to render before the db gets its data set.</p>

<p><strong>see what I tried bellow:</strong></p>

<pre><code>//page load
app.get('/', (req, res) =&gt; {

    //find all data in test table
    var articles;
    db.collection('test').find().toArray((err, result) =&gt; {
        if (err) return console.log(err)
        articles = result
    })

        // renders index.ejs and passes result to quotes
        res.render('./pages/index.ejs', {
            quotes: articles
        })
})
</code></pre>

<p><strong>my question is:</strong></p>

<p>How could I make sure that the render happens <strong>ONLY</strong> after my db queries have run and returned the data to a variable?</p>

<hr>

<blockquote>
  <p>Ultimately I would want to be able to do something like this:</p>
</blockquote>

<pre><code>//page load
app.get('/', (req, res) =&gt; {

    //find all data in table 1
    var AAA;
    db.collection('test1').find().toArray((err, result) =&gt; {
        if (err) return console.log(err)
        AAA = result
    })

     //find all data in table 2
    var BBB;
    db.collection('test2').find().toArray((err, result) =&gt; {
        if (err) return console.log(err)
        BBB = result
    })

     //find all data in table 3
    var CCC;
    db.collection('test3').find().toArray((err, result) =&gt; {
        if (err) return console.log(err)
        CCC = result
    })

        // renders index.ejs and passes result to quotes
        res.render('./pages/index.ejs', {
            quotes: AAA,
            quotes2: BBB,
            quotes3: CCC
        })
})
</code></pre>

<p>Any help or advice on this is appreciated. Thank you in advance.</p>