Skip to content

Conversation

@tuckyapps
Copy link

Hey,

Hope you are doing well!

Added the option, together with unit tests, to run a mongo server with replica sets. This is helpful when implementing transactions as it happens in our case.

All the best,

Santiago

@AlexisLeon
Copy link

Updates on this?

@AlexisLeon
Copy link

I'm getting this MongoDB deployment does not support retryable writes. Please add retryWrites=false to your connection string

Then fixed by adding "/?retryWrites=false" like this:

cli, err := Connect(ctx, mongoServer.URI() + "/?retryWrites=false")

But then this happened:
(IllegalOperation) Transaction numbers are only allowed on storage engines that support document-level locking

Is it only me?

@tuckyapps
Copy link
Author

Hi @AlexisLeon I have just fixed the issue, now I am using another storageEngine. Still waiting for them to accept the pull request but I am already using it on a private repo.

If you'd like, I can make it available to you so you can add it to your go module, given than my public fork will figure as ben's library and will not allow you to get my latest version.

@AlexisLeon
Copy link

@tuckyapps I'd love that. Thanks man

@tuckyapps
Copy link
Author

Done @AlexisLeon ! Until they accept the pull request, you can use this one: https://github.com/strikesecurity/strikememongo
:)

Copy link
Owner

@benweissmann benweissmann left a comment

Choose a reason for hiding this comment

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

Apologies for the delay! This is great -- just a few minor comments.

var mongoServer memongo.Server;

func TestMain(m *testing.M) {
mongoServer, err = memongo.StartWitOptions(&memongo.Options{MongoVersion: "4.2.1", ShouldUseReplica: true})
Copy link
Owner

Choose a reason for hiding this comment

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

Can we call this ConfigureReplicaSet? I think you need to be a little clearer in this documentation that this just configures the single server as a replica set -- but does not set up a secondary or actually perform replication. I'd suggest being pretty explicit here and say something like "This configures the Mongo server to be a replica set, and calls rs.initiate() after startup. It still only runs a single Mongo server."

if opts.ShouldUseReplica {
mongoCommand := fmt.Sprintf("mongo --port %d --retryWrites --eval \"rs.initiate()\"", opts.Port)
//nolint:gosec
cmd2 := exec.Command("bash", "-c", mongoCommand)
Copy link
Owner

Choose a reason for hiding this comment

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

You should pass in the arguments individual here (as on line 68) rather than passing a Sprintf-formatted string to exec.Command. Right now it's OK because you're just templating in a numeric port number, but there's risk here that some future change will introduce a command injection vulnerability.

if opts.ShouldUseReplica {
mongoCommand := fmt.Sprintf("mongo --port %d --retryWrites --eval \"rs.initiate()\"", opts.Port)
//nolint:gosec
cmd2 := exec.Command("bash", "-c", mongoCommand)
Copy link
Owner

Choose a reason for hiding this comment

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

Maybe rsInitiateCmd instead of cmd2?


// ---------- START OF REPLICA CODE ----------
if opts.ShouldUseReplica {
mongoCommand := fmt.Sprintf("mongo --port %d --retryWrites --eval \"rs.initiate()\"", opts.Port)
Copy link
Owner

Choose a reason for hiding this comment

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

Could you add a comment here about why you're passing --retryWrites?

@dsmontoya
Copy link

Hi, everyone! I can't start a replicaSet using strikememongo. I got this log:
ERROR INITIAING REPLICA: exit status 127
And *memongo.Server is nil
I'm overriding the binary path.

@saniales
Copy link

Hello to all contributors,

after multiple documented tries to contact @benweissmann through email, linkedin and here on Github,

I assumed with reasonable confidence that this project is abandoned*

To solve this problem, me and @tryvium-travels team decided to fork and maintain a new version of this very project.

You can check it at https://github.com/tryvium-travels/memongo

Please move the PRs there if you love to @tuckyapps @AlexisLeon @dsmontoya @antonyho

dgunay pushed a commit to lessthan3/memongo that referenced this pull request Nov 10, 2021
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.

6 participants