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

MongoDB connection fails with current default options #160

Open
freitzzz opened this issue Jun 19, 2020 · 14 comments
Open

MongoDB connection fails with current default options #160

freitzzz opened this issue Jun 19, 2020 · 14 comments

Comments

@freitzzz
Copy link

Since ssl option is set to false, it is not possible to establish a connection to a MongoDB server using an ecrypted connection (e.g. MongoDB Atlas). This option is not even featured in how to connect to each database in README.md. It would be great if the documentation on how to get started is updated as well as defaulting ssl option to true.

@adrai
Copy link
Contributor

adrai commented Jun 19, 2020

Would you like to create a PR?
regarding the default ssl option, I don’t think it should be set to true by default, because of backwards compatability

@freitzzz
Copy link
Author

Would you like to create a PR?
regarding the default ssl option, I don’t think it should be set to true by default, because of backwards compatability

Hi @adrai thanks for the quick response! I don't mind updating the documentation! However I'm currently on full work + education schedule and can't contribute, unfortunately. If I manage to have some time and nobody started working on this, I will make sure to update the issue to refer that I will update the documentation. Regarding backwards compatability, do you mind explaining a little better? I'm not used to the term so I can't seem to figure out the case here.

@adrai
Copy link
Contributor

adrai commented Jun 19, 2020

If we would change the defaults, which currently are:

{
    host: 'localhost',
    port: 27017,
    dbName: 'eventstore',
    eventsCollectionName: 'events',
    snapshotsCollectionName: 'snapshots',
    transactionsCollectionName: 'transactions'//,
    // heartbeat: 60 * 1000
  };

  var defaultOpt = {
    ssl: false
  };

and most of the users of this library use some sort of local network connection to the mongodb server, without any ssl; this would break their code...
This is why I would suggest to not change the defaults.

@freitzzz
Copy link
Author

If we would change the defaults, which currently are:

{
    host: 'localhost',
    port: 27017,
    dbName: 'eventstore',
    eventsCollectionName: 'events',
    snapshotsCollectionName: 'snapshots',
    transactionsCollectionName: 'transactions'//,
    // heartbeat: 60 * 1000
  };

  var defaultOpt = {
    ssl: false
  };

and most of the users of this library use some sort of local network connection to the mongodb server, without any ssl; this would break their code...
This is why I would suggest to not change the defaults.

Oh I see, makes sense. Thanks for the explanation!

@m-sterspace
Copy link

@freitzzz were you ever able to get this to connect to mongo atlas? When I run init() it doesn't seem to properly establish a connection...

@freitzzz
Copy link
Author

freitzzz commented Aug 7, 2020

@freitzzz were you ever able to get this to connect to mongo atlas? When I run init() it doesn't seem to properly establish a connection...

yes @m-sterspace

want me to send a code snippet?

@nanov
Copy link
Contributor

nanov commented Aug 13, 2020

i don't think that changing the defaults is an option. you provide a connection string with all the options that you might need and this should work.The defaults are, as the name suggests, defaults for most users which will use a local mongo connection.

@freitzzz
Copy link
Author

i don't think that changing the defaults is an option. you provide a connection string with all the options that you might need and this should work.The defaults are, as the name suggests, defaults for most users which will use a local mongo connection.

i dont think you can disable or enable SSL communication through the connection string

@chill-cod3r
Copy link

@freitzzz according to the mongodb docs you can - https://docs.mongodb.com/manual/reference/connection-string/#connection-options

@freitzzz
Copy link
Author

@freitzzz according to the mongodb docs you can - https://docs.mongodb.com/manual/reference/connection-string/#connection-options

Didn't know about this, thank you

@kojuka
Copy link

kojuka commented Apr 21, 2022

were you guys able to get this to work with mongo atlas? I'm struggling with some strange errors. my app seems to connect find, but when I try any query ie. getEventsByRevision, i get the following:
TypeError: Cannot read properties of undefined (reading 'find')

I've been using this package for a couple years with a mongo cluster I run in my own kubernetes cluster. I'm ready to give atlas a shot, but I'm having issues. Can anyone shed light on their config/settings to get this to work?

@freitzzz
Copy link
Author

were you guys able to get this to work with mongo atlas? I'm struggling with some strange errors. my app seems to connect find, but when I try any query ie. getEventsByRevision, i get the following: TypeError: Cannot read properties of undefined (reading 'find')

I've been using this package for a couple years with a mongo cluster I run in my own kubernetes cluster. I'm ready to give atlas a shot, but I'm having issues. Can anyone shed light on their config/settings to get this to work?

Mongo Atlas = Mongo Cloud, right? If so, yes.
Below you can find the public sources for a university project where this issue was risen.

https://github.com/freitzzz/insis-acervo-biblioteca-2019-2020/tree/master/acervo-biblioteca-mb/GestaoUtentesCommand

@kojuka
Copy link

kojuka commented Apr 21, 2022

@freitzzz

Yes. And using that repo I was able to get mine working! Thanks!

for others who struggle with this. My changes were this:

  1. Add ?retryWrites=true&w=majority to the end of the mongo url
  2. Add the following options
const eventStoreClient = eventstore({
  type: 'mongodb',
  url: config.MONGO_URL,
  eventsCollectionName: 'events', // optional
  snapshotsCollectionName: 'snapshots', // optional
  transactionsCollectionName: 'transactions', // optional
  timeout: 10000, // optional
  options: {
    ssl: true,
    autoReconnect: false,
    useNewUrlParser: true
  }
});

This is what I added.

 options: {
    ssl: true,
    autoReconnect: false,
    useNewUrlParser: true
  }

@freitzzz
Copy link
Author

@freitzzz

Yes. And using that repo I was able to get mine working! Thanks!

for others who struggle with this. My changes were this:

  1. Add ?retryWrites=true&w=majority to the end of the mongo url
  2. Add the following options
const eventStoreClient = eventstore({
  type: 'mongodb',
  url: config.MONGO_URL,
  eventsCollectionName: 'events', // optional
  snapshotsCollectionName: 'snapshots', // optional
  transactionsCollectionName: 'transactions', // optional
  timeout: 10000, // optional
  options: {
    ssl: true,
    autoReconnect: false,
    useNewUrlParser: true
  }
});

This is what I added.

 options: {
    ssl: true,
    autoReconnect: false,
    useNewUrlParser: true
  }

Glad to know it helped :)

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

No branches or pull requests

6 participants