vadimdemedes / mongorito

🍹 MongoDB ODM for Node.js apps based on Redux
1.38k stars 90 forks source link

Returning an object from an async function will run `find` #176

Closed EdenCoder closed 7 years ago

EdenCoder commented 7 years ago

Since the new API has the method then, when returning a model from an async function, node will try to run that then function without a query.

eg:

const test = async () => {
    let model = await Model.findById([id]);

    // return model
    return model;
};

const testagain = async () => {
    // await test
    await test (); // this will fail, throwing "Expected `query` to be object or undefined, got function"
};
EdenCoder commented 7 years ago

Removing the function then in query.js fixes this.

vadimdemedes commented 7 years ago

Good point, removing it right away.

vadimdemedes commented 7 years ago

3.0.1 is out with a fix, thanks!