Skip to content

Commit c9af7a5

Browse files
committed
Add examples to README.
1 parent 26c7bde commit c9af7a5

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

README.md

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,13 @@ bedrock.config.mongodb.name = 'my_project_dev'; // default: bedrock_dev
2727
bedrock.config.mongodb.host = 'localhost'; // default: localhost
2828
bedrock.config.mongodb.protocol = 'mongodb'; // default: mongodb
2929
bedrock.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:
3735
bedrock.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
4538
bedrock.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).
6154
MongoDB's documentation offers tons of great examples on how to authenticate
6255
using 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
7164
import {config} from '@bedrock/core';
7265

73-
config.mongodb.username = 'me';
74-
config.mongodb.password = 'password';
7566
config.mongodb.protocol = 'mongodb+srv';
7667
const {connectOptions} = config.mongodb;
68+
connectOptions.auth = {
69+
username: 'me',
70+
password: 'password'
71+
};
7772
// optional, only required if connecting to a replicaSet
7873
connectOptions.replicaSet = 'my_provider_replica_set';
7974
// optional, but required in production by many providers
8075
connectOptions.ssl = true;
8176
// optional, only required if your provider requires tls
8277
connectOptions.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
8581
connectOptions.authSource = 'my_provider_auth_db';
8682
```
8783
MongoDB provides [excellent docs on their connection strings](https://docs.mongodb.com/manual/reference/connection-string/)
8884

8985
You 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

Comments
 (0)