-
Notifications
You must be signed in to change notification settings - Fork 4
Mongo driver 4 rc no auth defaults #93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
74498c3
0ab6b11
3305ea7
45553c7
cb9bf96
00a6b14
fe982b0
1cf12d4
4b034b5
eeb3bd3
e3443f4
57b1967
0faecdf
3a875df
2054ae8
43e0cf9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,20 +27,13 @@ bedrock.config.mongodb.name = 'my_project_dev'; // default: bedrock_dev | |
| bedrock.config.mongodb.host = 'localhost'; // default: localhost | ||
| bedrock.config.mongodb.protocol = 'mongodb'; // default: mongodb | ||
| bedrock.config.mongodb.port = 27017; // default: 27017 | ||
| bedrock.config.mongodb.username = 'my_project'; // default: bedrock | ||
| bedrock.config.mongodb.password = 'password'; // default: password | ||
|
|
||
| // the mongodb database 'my_project_dev' and the 'my_project' user will | ||
| // be created on start up following a prompt for the admin user credentials | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These comments need to be brought into sync with these changes. |
||
|
|
||
| // alternatively, use `mongodb` URL format: | ||
| bedrock.config.mongodb.url = 'mongodb://localhost:27017/my_project_dev'; | ||
|
|
||
| // enable local collection if a local database is available | ||
| // the local database has similar options to primary database | ||
| // see lib/config.js for details | ||
| // bedrock.config.mongodb.local.enable = true; // default: false | ||
|
|
||
| // open some collections once the database is ready | ||
| bedrock.events.on('bedrock-mongodb.ready', async function() { | ||
| await database.openCollections(['collection1', 'collection2']); | ||
|
|
@@ -61,34 +54,37 @@ For documentation on database configuration, see [config.js](./lib/config.js). | |
| MongoDB's documentation offers tons of great examples on how to authenticate | ||
| using a myriad number of connection strings. | ||
|
|
||
| [Mongo Node 3.5 Driver connect docs](http://mongodb.github.io/node-mongodb-native/3.5/tutorials/connect/) | ||
| [Mongo Node 4.8 Driver connect docs](https://www.mongodb.com/docs/drivers/node/v4.8/fundamentals/connection/connect/) | ||
|
|
||
| [Mongo Node 3.5 Driver atlas docs](https://docs.mongodb.com/drivers/node#connect-to-mongodb-atlas) | ||
| [Mongo Node 4.8 Driver atlas docs](https://www.mongodb.com/docs/atlas/driver-connection/?tck=docs_driver_nodejs) | ||
|
|
||
| You can also connect to access-enabled mongo servers using some small changes to the | ||
| You can also connect to auth-enabled mongo servers using some small changes to the | ||
| `config.mongodb.connectOptions`: | ||
| ```js | ||
| import {config} from '@bedrock/core'; | ||
|
|
||
| config.mongodb.username = 'me'; | ||
| config.mongodb.password = 'password'; | ||
| config.mongodb.protocol = 'mongodb+srv'; | ||
| const {connectOptions} = config.mongodb; | ||
| connectOptions.auth = { | ||
| username: 'me', | ||
| password: 'password' | ||
| }; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't want to support this, only |
||
| // optional, only required if connecting to a replicaSet | ||
| connectOptions.replicaSet = 'my_provider_replica_set'; | ||
| // optional, but required in production by many providers | ||
| connectOptions.ssl = true; | ||
| // optional, only required if your provider requires tls | ||
| connectOptions.tls = true; | ||
| // the `authSource` option replaces the older `authDB` option | ||
| // it should be specified or else it will be the `mongodb.name` | ||
| // the `authSource` is database to authenticate against | ||
| // it should be specified or it will default to the database | ||
| // you're connecting to | ||
| connectOptions.authSource = 'my_provider_auth_db'; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be removed too, right? It looks like it can be done via the |
||
| ``` | ||
| MongoDB provides [excellent docs on their connection strings](https://docs.mongodb.com/manual/reference/connection-string/) | ||
|
|
||
| You can connect using a url by setting: | ||
| ```js | ||
| config.mongodb.url = 'mongodb://myDBReader:D1fficultP%[email protected]:27017/?authSource=admin'; | ||
| config.mongodb.url = 'mongodb://myDBReader:D1fficultP%[email protected]:27017/myDatabase?authSource=admin'; | ||
| ``` | ||
|
|
||
| ## Requirements | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,17 +6,18 @@ import {config} from '@bedrock/core'; | |
| config.mongodb = {}; | ||
| // Note: `config.mongodb.url` is not set by default. When it is not set, it | ||
| // will be assembled from from the `config.mongodb.name`, `config.mongodb.host`, | ||
| // and `config.mongodb.port`. When it is set, those values, any authentication | ||
| // credentials, and any server options will be parsed from the URL and override | ||
| // the broken-down configuration options set here. | ||
| // and `config.mongodb.port`. When it is set, those values and any server | ||
| // options will be parsed from the URL and override the broken-down | ||
| // configuration options set here. | ||
| // | ||
| // At a minimum, the URL must specify a host, port, and database name. It may | ||
| // omit a username and password if those are provided as | ||
| // `config.mongodb.username` and `config.mongodb.password`, otherwise those | ||
| // `config.mongodb.connnectOptions.auth.username` and | ||
| // `config.mongodb.connectOptions.auth.password`, otherwise those | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We'll want to bring these comments in sync after removing the extra options. |
||
| // values will be removed from the URL to prevent their logging and a | ||
| // separate authentication call will be made after connecting. | ||
| // | ||
| // `mongodb.connectOptions` will override any specified in the URL. | ||
| // `mongodb.connectOptions` may override any specified in the URL. | ||
| // | ||
| // format: mongodb://[username:password@]host1[:port1][,host2[:port2], | ||
| // ...[,hostN[:portN]]][/[database][?options]] | ||
|
|
@@ -26,11 +27,6 @@ config.mongodb.name = 'bedrock_dev'; | |
| config.mongodb.host = 'localhost'; | ||
| config.mongodb.port = 27017; | ||
| config.mongodb.protocol = 'mongodb'; | ||
| config.mongodb.username = undefined; | ||
| config.mongodb.password = undefined; | ||
| config.mongodb.adminPrompt = true; | ||
| // always authenticate to mongodb even when auth is not required by mongodb | ||
| config.mongodb.forceAuthentication = false; | ||
| config.mongodb.authentication = { | ||
| // used by MongoDB >= 3.0 | ||
| // authMechanism: 'SCRAM-SHA-1' | ||
|
|
@@ -46,9 +42,6 @@ config.mongodb.connectOptions = { | |
| // it is recommended to set either ssl or tls to true in production | ||
| // ssl: true | ||
| // tls: true | ||
| // authSource is the database you authenticate against | ||
| // it often needs to be set explicitly | ||
| // authSource: 'admin' | ||
| }; | ||
|
|
||
| // this is used when writing to the database | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add something here that says that all of these options, if needed, must be provided via the database url config option?