Bluebird .then(): not working as it should
<p>I just started working with promises and Bluebird. While debugging I can see that my function is executed twice: </p>

<p>First I get this error: <code>TypeError: Uncaught error: Cannot read property 'then' of undefined</code></p>

<p>Then I see the function is executed again, and <code>.then()</code> is executed successfully. Also I get the correct information printed in the console.</p>

<p>Why is this happening? The whole reason I'm implementing promises is because I want to wait with executing the <code>then()</code>-action, because my data has to be retrieved first. But still the code jumps to the .then() action too early.</p>

<p>Why is this happening and how can I prevent it?</p>

<p>Here's my code:</p>

<pre><code>exports.findUser = function(userId){

    var ObjectID = require('mongodb').ObjectID;
    var u_id = new ObjectID(userId);

    db.collection('users')
        .findOne({'_id': u_id})
        .then(function(docs) { //executed twice, first time error, second time success
            console.log(docs); //prints correct info once executed
            return docs;
        })
        .catch(function(err) {
            console.log(err);
        });
};
</code></pre>