keystone-classic icon indicating copy to clipboard operation
keystone-classic copied to clipboard

Add documentation on using MongoDB Connection Strings

Open stennie opened this issue 5 years ago • 5 comments

The documentation should include more information on setting the MongoDB Connection string and using a non-local database.

Related:

  • #4782 (MongoDB credentials configuration)
  • #4795 (Can I install Keystone using MongoDB Atlas)

stennie avatar Sep 12 '18 00:09 stennie

My experience was that I could not get keystone to support the standard mongo+srv type addresses which Atlas publishes. Instead I had to use the older clustering URL styles of mongo://server1:port,server2:port,server3:27017/db_name?retryWrites=true&ssl=true&authSource=admin

I am also using a password generator so had to play around removing special characters. hash, tilda, etc.

chanoch avatar Oct 06 '18 10:10 chanoch

its possible by editing the keystone.init in keystone.js file:

keystone.init({
 'mongo' : 'mongodb://abc_key:xxxxxxxxxxxxxxxxxxxxxxxxxxxx'
})

icdindia avatar Oct 17 '18 07:10 icdindia

@icdindia Although you can add the value directly in your keystone.init, best practice is generally to keep credentials outside of version control.

You can set the MongoDB URI via a .env file in your keystone project directory or an alias in the environment. The config checks for a number of [common environment variables|https://github.com/keystonejs/keystone/blob/master/lib/core/initDatabaseConfig.js#L7].

Regards, Stennie

stennie avatar Oct 17 '18 09:10 stennie

@stennie I had this issue of connecting to atlas using keystone as well. Initially I was using the mongodb+srv://<username>:<password>@clustername.mongodb.net/test?retryWrites=true&w=majority link provided by atlas for the connections.

Due to the errors I tried out the old URI format specified in the mongodb docs. So basically to get keystone to connect to the atlas database we have to use the below URI format

mongodb://<username>:<password>@<replicaset0name>.mongodb.net:27017,<replicaset1name>.mongodb.net27017,<replicaset2name>.mongodb.net:27017/test?retryWrites=true&ssl=true&authSource=admin&replicaSet=<replicasetname(excluding last digit)>

the replica set names can be found from the clusters tab in the atlas console.

Amrithnath avatar Jul 23 '19 10:07 Amrithnath

@Amrithnath thanks so much bro!!! Works! It saved me :)))

@stennie I had this issue of connecting to atlas using keystone as well. Initially I was using the mongodb+srv://<username>:<password>@clustername.mongodb.net/test?retryWrites=true&w=majority link provided by atlas for the connections.

Due to the errors I tried out the old URI format specified in the mongodb docs. So basically to get keystone to connect to the atlas database we have to use the below URI format

mongodb://<username>:<password>@<replicaset0name>.mongodb.net:27017,<replicaset1name>.mongodb.net27017,<replicaset2name>.mongodb.net:27017/test?retryWrites=true&ssl=true&authSource=admin&replicaSet=<replicasetname(excluding last digit)>

Kopakov avatar Aug 09 '19 15:08 Kopakov