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

Model.findOneAndUpdate does not allow for a session param #8396

Closed
florianbepunkt opened this issue Dec 3, 2019 · 3 comments
Closed

Model.findOneAndUpdate does not allow for a session param #8396

florianbepunkt opened this issue Dec 3, 2019 · 3 comments
Labels
docs This issue is due to a mistake or omission in the mongoosejs.com documentation
Milestone

Comments

@florianbepunkt
Copy link

I have a session object and want a Model.findOneAndUpdate operation to be part of a transaction. I stated a question on SO here, but inspecting the typescript definitions I think this is a bug / missing feature in mongoose. You can't pass a session param to Model.findOneAndUpdate()

Do you want to request a feature or report a bug?
Not sure, kind of both

What is the current behavior?
Model. findOneAndUpdate() does not allow to pass a session in TypeScript. The interface QueryFindOneAndUpdateOptions does not have a session param. The node.js driver however allows to pass a session object: http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#findOneAndUpdate

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

const doc = await AnyModel.findOneAndUpdate(
{ query: {} },
{
$inc: { value: 1 }
},
{ session: session }
);

What is the expected behavior?
You should be able to pass a session to findOneAndUpdate

What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
mongoose 5.7.12

Link to SO:
https://stackoverflow.com/questions/59156202/use-transaction-in-model-findoneandupdate

@florianbepunkt
Copy link
Author

Okay, it looks like it is just a TypeScript problem and QueryFindOneAndUpdateOptions interface should include session?: ClientSession;

Do you maintain the typescript definitions? I could open a PR

@Fonger
Copy link
Contributor

Fonger commented Dec 7, 2019

Okay, it looks like it is just a TypeScript problem and QueryFindOneAndUpdateOptions interface should include session?: ClientSession;

Do you maintain the typescript definitions? I could open a PR

AFAIK typescript definitions are maintained by community. There’s no official one.

@vkarpov15
Copy link
Collaborator

@florianbepunkt I updated our docs. We don't maintain typescript definitions currently.

@vkarpov15 vkarpov15 added the docs This issue is due to a mistake or omission in the mongoosejs.com documentation label Dec 8, 2019
@vkarpov15 vkarpov15 modified the milestones: 5.7.15, 5.8.0 Dec 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs This issue is due to a mistake or omission in the mongoosejs.com documentation
Projects
None yet
Development

No branches or pull requests

3 participants