@@ -27,20 +27,13 @@ bedrock.config.mongodb.name = 'my_project_dev'; // default: bedrock_dev
2727bedrock .config .mongodb .host = ' localhost' ; // default: localhost
2828bedrock .config .mongodb .protocol = ' mongodb' ; // default: mongodb
2929bedrock .config .mongodb .port = 27017 ; // default: 27017
30- bedrock .config .mongodb .username = ' my_project' ; // default: bedrock
31- bedrock .config .mongodb .password = ' password' ; // default: password
3230
3331// the mongodb database 'my_project_dev' and the 'my_project' user will
3432// be created on start up following a prompt for the admin user credentials
3533
3634// alternatively, use `mongodb` URL format:
3735bedrock .config .mongodb .url = ' mongodb://localhost:27017/my_project_dev' ;
3836
39- // enable local collection if a local database is available
40- // the local database has similar options to primary database
41- // see lib/config.js for details
42- // bedrock.config.mongodb.local.enable = true; // default: false
43-
4437// open some collections once the database is ready
4538bedrock .events .on (' bedrock-mongodb.ready' , async function () {
4639 await database .openCollections ([' collection1' , ' collection2' ]);
@@ -61,34 +54,37 @@ For documentation on database configuration, see [config.js](./lib/config.js).
6154MongoDB's documentation offers tons of great examples on how to authenticate
6255using a myriad number of connection strings.
6356
64- [ Mongo Node 3.5 Driver connect docs] ( http ://mongodb.github.io/ node-mongodb-native/3.5/tutorials /connect/)
57+ [ Mongo Node 4.8 Driver connect docs] ( https ://www. mongodb.com/docs/drivers/ node/v4.8/fundamentals/connection /connect/)
6558
66- [ Mongo Node 3.5 Driver atlas docs] ( https://docs .mongodb.com/drivers/node#connect-to-mongodb- atlas )
59+ [ Mongo Node 4.8 Driver atlas docs] ( https://www .mongodb.com/docs/ atlas/driver-connection/?tck=docs_driver_nodejs )
6760
68- You can also connect to access -enabled mongo servers using some small changes to the
61+ You can also connect to auth -enabled mongo servers using some small changes to the
6962` config.mongodb.connectOptions ` :
7063``` js
7164import {config } from ' @bedrock/core' ;
7265
73- config .mongodb .username = ' me' ;
74- config .mongodb .password = ' password' ;
7566config .mongodb .protocol = ' mongodb+srv' ;
7667const {connectOptions } = config .mongodb ;
68+ connectOptions .auth = {
69+ username: ' me' ,
70+ password: ' password'
71+ };
7772// optional, only required if connecting to a replicaSet
7873connectOptions .replicaSet = ' my_provider_replica_set' ;
7974// optional, but required in production by many providers
8075connectOptions .ssl = true ;
8176// optional, only required if your provider requires tls
8277connectOptions .tls = true ;
83- // the `authSource` option replaces the older `authDB` option
84- // it should be specified or else it will be the `mongodb.name`
78+ // the `authSource` is database to authenticate against
79+ // it should be specified or it will default to the database
80+ // you're connecting to
8581connectOptions .authSource = ' my_provider_auth_db' ;
8682```
8783MongoDB provides [ excellent docs on their connection strings] ( https://docs.mongodb.com/manual/reference/connection-string/ )
8884
8985You can connect using a url by setting:
9086``` js
91- config .
mongodb .
url = ' mongodb://myDBReader:D1fficultP%[email protected] :27017/?authSource=admin' ;
87+ config .
mongodb .
url = ' mongodb://myDBReader:D1fficultP%[email protected] :27017/myDatabase ?authSource=admin' ;
9288```
9389
9490## Requirements
0 commit comments