Keystone-classic: Add documentation on using MongoDB Connection Strings

Created on 12 Sep 2018  路  5Comments  路  Source: keystonejs/keystone-classic

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)
4.x candidate documentation

Most helpful comment

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

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

All 5 comments

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.

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

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

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

webteckie picture webteckie  路  5Comments

calebmcelroy picture calebmcelroy  路  3Comments

joernroeder picture joernroeder  路  5Comments

javierpelozo picture javierpelozo  路  5Comments

josephg picture josephg  路  4Comments