Access to external MongoDB using certificates #6177

This discussion has been migrated from our Github Discussion #6177


daguadofernandez230d ago

Hi:

I´m trying to connect Strapi to a MongoDB cluster with certicates. My database.json is:

{
	"defaultConnection": "default",
	"connections": {
		"default": {
			"connector": "strapi-hook-mongoose",
			"settings": {
				"uri": "mongodb://myuser:[mypassword@mongo-cluster-node01.domain.com](mailto:mypassword@mongo-cluster-node01.domain.com):27017,mongo-cluster-node02.domain.com:27017,mongo-cluster-node03.domain.com:27017/ddbbname?replicaSet=replicasetname&ssl=true&sslCAFile=/tmp/certificates/mongoCA.crt&sslPEMKeyFile=/tmp/certificates/mycertificate.domain.com.pem&authSource=admin"
			},
			"options": {
				"ssl": false
			}
		}
	}
}

Is supported access a MongoDB with a URI and certificates? is correct this connection string?

Thanks

Responses to the discussion on Github


derrickmehaffy230d ago

Collaborator

"connector": "strapi-hook-mongoose",

You are using a fairly old version of Strapi if you still have the hook set there. What version are you running?


daguadofernandez230d ago

Author

Hi…

Sorry by the delay… the version is strapi 3.0.0-alpha.26.2

I have try with “mongoose” connector:

root@vmstrapi:~/myproject# strapi start
[2020-05-12T17:01:06.712Z] debug Server wasn’t able to start properly.
[2020-05-12T17:01:06.712Z] error (hook:mongoose) takes too long to load
(hook:mongoose) takes too long to load

Regards.


derrickmehaffy229d ago

Collaborator

strapi 3.0.0-alpha.26.2 This version is no longer supported and hasn’t been in over a year.


daguadofernandez229d ago

Author

Hi:

I have use latest version 3.0.0-beta.20.3

image

{
“defaultConnection”: “default”,
“connections”: {
“default”: {
“connector”: “mongoose”,
“settings”: {
“uri”: “mongodb://myuser:mypassword@mongo-cluster-node01.domain.com:27017,mongo-cluster-node02.domain.com:27017,mongo-cluster-node03.domain.com:27017/ddbbname?replicaSet=replicasetname&ssl=true&sslCAFile=/tmp/certificates/mongoCA.crt&sslPEMKeyFile=/tmp/certificates/mycertificate.domain.com.pem&authSource=admin
},
“options”: {
“ssl”: false
}
}
}
}

If i use a MongoDb standalone very basic connect without problem.

image

Regards.


sunnysonx229d ago

Does the option “ssl”: false conflict with SSL true from Mongo string?


daguadofernandez228d ago

Author

Hi:

I have try with both options “true” and “false” and the result is the same:

image

Reagards.


sunnysonx227d ago

@daguadofernandez I had the same issue a few days ago, in my case the problem was in the password of Mongo, as I copied it Encoded from Mongo string URL, but Strapi accepts it only as Decoded.


sunnysonx227d ago

Also, can you connect to your external MongoDB from Mongo Compass? If you can, problem is 100% the password, but if you can’t, then you should verify if your Mongo instance has external access for port 27017. Also, be aware to whitelist your server’s IP and allow access only from it.


daguadofernandez224d ago

Author

Hi:

I´m using decode password, in text plane.

I can connect from Mongo Compass and Studio 3D without problem.


sunnysonx224d ago

So that’s the problem, try to pass the password as encoded in strapi.


daguadofernandez224d ago

Author

Hi:

How encode?? base64???

Thanks


sunnysonx224d ago

Sorry, my bad, it should be decoded in strapi* and encoded in Mongo compass.
In strapi I have it stored like this:
"password": "1N@3ZbFE3@e"
But in Mongo compass I use it like this:
1N%403ZbFE3%40e


sunnysonx224d ago

Also, make sure you use the right environment. Maybe you use development, but you set the password only for production.