Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

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

[Enh] Please addition session for mongoose 5.2.x #3

Open
zinzinday opened this issue Aug 3, 2018 · 0 comments
Open

[Enh] Please addition session for mongoose 5.2.x #3

zinzinday opened this issue Aug 3, 2018 · 0 comments

Comments

@zinzinday
Copy link

mongoose.startSession().then(async (session) => {
        session.startTransaction();
        try {
            let opts = {session, validateBeforeSave: true};
            let user = await new User(req.body).save(opts);
            let wallet = await new Wallet({user: user.id}).save(opts);
            await session.commitTransaction();
            res.send({success: true, data: user});
        } catch (e) {
            await session.abortTransaction();
            return next(e);
        }
})

Current debug output miss session.id to command query find exist validate

Mongoose: users.find({ _id: { '$in': [ 'bdd7a1f9-b57b-45e3-ab85-9b9a7a956ec1' ] } }, { fields: { _id: 1 } })
wallet validation failed: user: user with id bdd7a1f9-b57b-45e3-ab85-9b9a7a956ec1 does not exists

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants