Skip to content
New issue

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

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

Already on GitHub? # to your account

@feathersjs/mongodb doesn't fully work with transaction sessions #2694

Closed
joezappie opened this issue Jul 17, 2022 · 1 comment · Fixed by #2699
Closed

@feathersjs/mongodb doesn't fully work with transaction sessions #2694

joezappie opened this issue Jul 17, 2022 · 1 comment · Fixed by #2699

Comments

@joezappie
Copy link
Contributor

joezappie commented Jul 17, 2022

I noticed on services that used transactions when trying to create a document, context.result is undefined.

Looking through the adapter code, the $create method passes the params.mongodb object to the insertMany and insertOne but does not pass it to the subsequent findMany or findOne:

// Current Code
const promise = Array.isArray(data)
      ? model
          .insertMany(data.map(setId), writeOptions)
          .then(async (result) =>
            Promise.all(Object.values(result.insertedIds).map(async (_id) => model.findOne({ _id })))
          )
      : model
          .insertOne(setId(data), writeOptions)
          .then(async (result) => model.findOne({ _id: result.insertedId }))

// Working Code
const promise = Array.isArray(data)
      ? model
          .insertMany(data.map(setId), writeOptions)
          .then(async (result) =>
            Promise.all(Object.values(result.insertedIds).map(async (_id) => model.findOne({ _id }, params.mongodb)))
          )
      : model
          .insertOne(setId(data), writeOptions)
          .then(async (result) => model.findOne({ _id: result.insertedId }, params.mongodb))

I tested this and my transactions begin working again.

I looked over the rest of the adapter and looks like every other call passes the session in properly but haven't used them yet.

Steps to reproduce

  1. Start a mongo transaction and pass session in under params.mongodb.session.
  2. Try to create a document
  3. Check that context.result is undefined

Expected behavior

Created document should be returned as the result

Actual behavior

Result is undefined.

System configuration

Tell us about the applicable parts of your setup.

Module versions (especially the part that's not working):
5.0.0-pre.27

NodeJS version:
v16.16.0

Operating System:
Linux debian

Browser Version:
N/A

React Native Version:
N/A

Module Loader:
N/A

@daffl
Copy link
Member

daffl commented Jul 19, 2022

Good catch, thank you! Will be fixed via #2699

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants