node-eventstore icon indicating copy to clipboard operation
node-eventstore copied to clipboard

MongoDB connection fails with current default options

Open joaomagfreitas opened this issue 5 years ago • 14 comments

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.

joaomagfreitas avatar Jun 19 '20 20:06 joaomagfreitas

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

adrai avatar Jun 19 '20 20:06 adrai

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.

joaomagfreitas avatar Jun 19 '20 21:06 joaomagfreitas

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.

adrai avatar Jun 19 '20 21:06 adrai

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!

joaomagfreitas avatar Jun 19 '20 21:06 joaomagfreitas

@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...

m-sterspace avatar Aug 04 '20 19:08 m-sterspace

@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?

joaomagfreitas avatar Aug 07 '20 18:08 joaomagfreitas

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.

nanov avatar Aug 13 '20 13:08 nanov

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

joaomagfreitas avatar Aug 14 '20 09:08 joaomagfreitas

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

chill-cod3r avatar Sep 15 '20 20:09 chill-cod3r

@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

joaomagfreitas avatar Sep 15 '20 20:09 joaomagfreitas

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?

kojuka avatar Apr 21 '22 08:04 kojuka

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

joaomagfreitas avatar Apr 21 '22 08:04 joaomagfreitas

@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
  }

kojuka avatar Apr 21 '22 16:04 kojuka

@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 :)

joaomagfreitas avatar Apr 22 '22 21:04 joaomagfreitas