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

Add support for MongoDB Transactions #715

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

LucGranato
Copy link

@LucGranato LucGranato commented Oct 2, 2018

Hey guys!

I added support for MongoDB Transactions by using sessions.

Thanks!

Closes #821

@LucGranato
Copy link
Author

Hello people!

Do you want me to do something more?
I want to cooperate as best as I can, and personally I'm interested in making this functionality available as soon as possible.

Thank you very much!

@simison
Copy link
Member

simison commented Nov 24, 2019

Thanks for the PR! Could you elaborate a little more on why this would be a great addition? Thanks! :-)

@koresar
Copy link
Contributor

koresar commented Nov 25, 2019

If I understand correctly, people want the Agenda CRUD operations to be part of an ACID MongoDB transaction. (This excellent blog post gives me a hint to say so.)

Pseudo code of creating a user in a databse:

Start Transaction.
1. Create User Document.
2. Create Agenda Job Document
Commit Transaction.

Either both or none of the documents will be created in the DB.

Copy link

@ScreamZ ScreamZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beside some small questions, this looks good to me. Thanks

@koresar That's it! That way you can schedules jobs as being part of an multi-document transaction condition. Which is cool.

// eslint-disable-next-line prefer-rest-params
noCallback(arguments, 2);
noCallback(arguments, 3);
Copy link

@ScreamZ ScreamZ Nov 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be a bad reviewer but I don't get why this is changing from 2 to 3 here 😅Can yoy give me some explanations ?

Thanks

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will throw an error when passing the new mongoOptions parameter without changing from 2 to 3.
This change may be considered as breaking change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this is a breaking change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -33,6 +34,9 @@ class Job {
this.agenda = args.agenda;
delete args.agenda;

this.mongoOptions = args.mongoOptions || {};
delete args.mongoOptions;
Copy link

@ScreamZ ScreamZ Nov 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the point of the delete instruction here ? I'm afraid this code can cause side effects as objects arguments are passed as reference in JS.

What do you think ? :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For sure!
Probably I follow the delete from line 35 without thinking about the consequences.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The object should be cloned before mutating.


describe('transactions', () => {
before(async function () {
if(!mongoURI.includes('replicaSet')){
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the condition should relies on v4 checking

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How to check if that's v4?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure in units tests, but I mongo generally you can use this: https://stackoverflow.com/a/16932830/5320409

Maybe we can add a check at instantiation that turn a value in the root class and throw an error if you try to pass a session object on <v4 function ?

Tell me if you've a better idea ? :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your suggestions are perfect.

@shanrauf
Copy link

May I ask what the status is on this PR?

@koresar
Copy link
Contributor

koresar commented Apr 13, 2020

The status is, I think, abandoned.

@shanrauf would you like to finish it? Maybe even restart from the latest master branch?

@shanrauf
Copy link

@koresar Sure. I'll submit a PR on Wednesday.

@shanrauf
Copy link

It seems like @LucGranato plans to complete this PR, so I'll hold off on this one.

@LucGranato
Copy link
Author

Hey, I come back!

Since I made this pull request, I'm using this version on my project, and I had zero problems so far.

@koresar you are 100% right about the use case, and thanks for your help.

@ScreamZ thanks for your review. I just answered your questions about the code.

@shanrauf did you made any improvement? Let's finish this PR together.

I'm pleased to see this feature going live!
Thanks, folks!

@makinde
Copy link

makinde commented Jul 17, 2020

@LucGranato , looking forward to this landing. Any progress?

@koresar
Copy link
Contributor

koresar commented Jul 18, 2020

@makinde if your could push this feature forward by solving all the issues everyone would love you. 😃

@harisvsulaiman
Copy link
Member

harisvsulaiman commented Jan 27, 2021

Hi. I’m gonna take a stab at it. Is it fine if I open a new pull req

Suggestions

  1. Should sessions be optional?

@simison @LucGranato @koresar

@koresar
Copy link
Contributor

koresar commented Jan 27, 2021

Thanks mate!

@ScreamZ
Copy link

ScreamZ commented Feb 19, 2021

Dudes any update on that ?

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

Successfully merging this pull request may close these issues.

Support for MongoDB 4 transactions
8 participants