By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement . We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recently upgraded to mongoose 4.0.2. The following code was working previously, but now results in the document being created but not passed to the callback:

Milestone.findOneAndUpdate({
    ......
}, {
    ......
}, {upsert: true}, function(err, res) {
    // err === null
    // res === null
    done(err, res);
});

This is only occurring on upsert . I can verify the document is created, but both err and res are consistently null. If I call the function again (now that the document exists) it works as expected.

mongoose: 4.0.2
node: v0.12.2
mongodb: 2.6.9

Use the new: true option, see 4.0 release notes notes on #2262 .

Milestone.findOneAndUpdate({
    ......
}, {
    ......
}, {upsert: true, 'new': true}, function(err, res) {
    // err === null
    // res === null
    done(err, res);
});
aminnaggar, rclayton-the-terrible, spsiddarthan, maidanskyi, generalgmt, duhovny, cymruu, octet-stream, anatoly314, CollegeFellow, and 16 more reacted with thumbs up emoji mirajehossain reacted with heart emoji All reactions This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary label Apr 29, 2015