MongoDB Atlas Connection Strings?

Hi guys,

Trying to connect n8n to a MongoDB Atlas instance. Atlas provides connection strings which do not have a port if you select a connection string with Node 3 or later. For earlier versions of the Node driver, it does include a URL of the form you’re using (hostname:port), HOWEVER, it has three different URLs and the example code to connect appears to require all three:

var MongoClient = require('mongodb').MongoClient;

var uri = "mongodb:// **user** : **<password>** @cluster-shard-*.mongodb.net:27017,cluster-shard-*.mongodb.net:27017,cluster-shard-*.mongodb.net:27017/test?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin&retryWrites=true&w=majority";
MongoClient.connect(uri, function(err, client) {
  const collection = client.db("test").collection("devices");
  // perform actions on the collection object
  client.close();
});

I looked at n8n’s MongoDB node and see you only support a single URL. Any insights on how to connect to Atlas using the existing MongoDB node? Perhaps I am missing something?

In any case, I’d suggest giving an option to let someone pass in a connection string. You might consider this for all of your DB nodes as many DBs are easily configured with a connection string.

Thanks!

Sadly have not much experience with MongoDB so can not really help you here. There is however already a pull-request open to allow also connection strings:

Sadly did not find time yet to properly review and test it. Once it is merged your problem should be solved.

Anyway, no matter if a port is given or not, one will be used. So I guess if none is provided it will be the default port. Can also not imagine that all 3 will be needed. Guess one would suffice and the other two are simply backups in case another one is currently down. But again have not much experience with MongoDB.

Got now reviewed, slightly improved and merged. Will be released with the next version.

Got released with [email protected]

1 Like