Node.js detect when two mongoose find are finished
<p>I'm trying to initialize two input with autocomplete with this <a href="https://www.devbridge.com/sourcery/components/jquery-autocomplete/">library</a>. When I load my page, I will trigger an Ajax to initialize two input text.</p>

<p>But I don't know how I can detect when all my mongoose find are completed.</p>

<p>Here is my server side code :</p>

<pre><code>app.post('/init/autocomplete', function(req, res){
    var autocomplete = {
        companies: [],
        offices: []
    };

    // Find all companies
    Company.find({}, function(err, companies) {
        if (err) throw err;

        companies.forEach(function(company) {
            autocomplete.companies.push({value: company.name})
        });

        console.log('One');
    });

    // Find all offices
    Office.find({}, function(err, offices) {
        if (err) throw err;

        offices.forEach(function(office) {
            autocomplete.offices.push({value: office.name})
        });

        console.log('Two');
    });

    console.log('Three');

    // res.json(autocomplete);
});
</code></pre>

<p>I know than the find method is async. That is why I see my console.log() in this order :</p>

<pre><code>Three
One
Two
</code></pre>

<p>How can I do to trigger <code>console.log('Three');</code> when the <code>Company.find</code> and <code>Office.find</code> are finished ? </p>

<p>I want to see the <code>console.log('Three');</code> at the last position.</p>

<p><strong>Edit :</strong></p>

<p>I think I can do this way :</p>

<pre><code>app.post('/init/autocomplete', function(req, res){
    var autocomplete = {
        companies: [],
        offices: []
    };

    // Find all companies
    Company.find({}, function(err, companies) {
        if (err) throw err;

        companies.forEach(function(company) {
            autocomplete.companies.push({value: company.name})
        });

        // Find all offices
        Office.find({}, function(err, offices) {
            if (err) throw err;

            offices.forEach(function(office) {
                autocomplete.offices.push({value: office.name})
            });

            res.json(autocomplete);
        });
    });
});
</code></pre>

<p>But I don't know if it's the good way. Maybe using promise will be better ? I'm open for all suggestions.</p>