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

Allow documents to detach from sessions once they have ended #10306

Closed
chriskrogh opened this issue May 29, 2021 · 0 comments
Closed

Allow documents to detach from sessions once they have ended #10306

chriskrogh opened this issue May 29, 2021 · 0 comments
Labels
new feature This change adds new functionality, like a new method or class
Milestone

Comments

@chriskrogh
Copy link

Do you want to request a feature or report a bug?
Request a feature / Report a bug (not sure what expected behaviour is for this specific cse)

What is the current behavior?
MongoError: Use of expired sessions is not permitted is thrown when populating a document that was created in a session (See the src/index.ts in the repo below for an easy to read example).

If the current behavior is a bug, please provide the steps to reproduce.

repo for repro

  • model A and model B exist such that model A has a ref to model B
  • start a session & transaction
  • create a document using model B, then a document using model A with the reference (ObjectId) to the B document
  • commit the transaction & end the session
  • try to populate the instance of B on A
  • error

To avoid this, one can simply use the existing B doc when creating A instead of using B's id and a reference. However, this error is actually thrown if any of the subdocuments of B on A are populated as well (e.g if B had a C and we tried to populate C).

What is the expected behavior?
I understand that because A and B were created in a session, that subsequent writes that occur once the session has ended will still be "linked" to a dead session and that's what's throwing the error here. However, I feel like there should be an easy way to detach a document from a session (especially since the session successfully ended).

What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Versions are visible in the repo attached.

@IslandRhythms IslandRhythms added the new feature This change adds new functionality, like a new method or class label Jun 4, 2021
@vkarpov15 vkarpov15 added this to the 5.13 milestone Jun 4, 2021
vkarpov15 added a commit that referenced this issue Jun 16, 2021
…documents that were loaded in the session after calling `endSession()`

Fix #10306
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature This change adds new functionality, like a new method or class
Projects
None yet
Development

No branches or pull requests

3 participants