-
Notifications
You must be signed in to change notification settings - Fork 4
Update to driver v6. #107
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
Update to driver v6. #107
Changes from all commits
be72896
74ce575
b6d6acc
af50c20
a1abddc
6c2e57a
dfb4f4c
07e27c7
4c82716
25afd96
6e36c08
01f805a
7fd22bc
f9d2b46
3eb8fc8
cf85e25
2ca5beb
cadcc2c
58cb6a5
25a9953
2499d8e
1be6a4f
fc1f2ce
67e42cd
3c869b2
1c10876
e13469a
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 |
|---|---|---|
|
|
@@ -25,22 +25,17 @@ import * as database from '@bedrock/mongodb'; | |
| // custom configuration | ||
| 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.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 | ||
|
|
||
| // alternatively, use `mongodb` URL format: | ||
| // alternatively, use `mongodb` URL format (preferred for deployments): | ||
| 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']); | ||
|
|
@@ -58,15 +53,20 @@ bedrock.start(); | |
| For documentation on database configuration, see [config.js](./lib/config.js). | ||
|
|
||
| ### Connecting and Authenticating | ||
| MongoDB's documentation offers tons of great examples on how to authenticate | ||
| using a myriad number of connection strings. | ||
| MongoDB's documentation provides 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 Driver connect docs](https://www.mongodb.com/docs/drivers/node/current/fundamentals/connection/connect/) | ||
|
|
||
| [Mongo Node 3.5 Driver atlas docs](https://docs.mongodb.com/drivers/node#connect-to-mongodb-atlas) | ||
| You can connect using a url by setting: | ||
| ```js | ||
| config.mongodb.url = 'mongodb://myDBReader:D1fficultP%[email protected]:27017/?authSource=admin'; | ||
| ``` | ||
|
|
||
| You can also connect to access-enabled mongo servers using some small changes to the | ||
| `config.mongodb.connectOptions`: | ||
| `config.mongodb.connectOptions`, however, the `config.mongodb.url` option is highly | ||
| preferable and should cover most use cases: | ||
|
|
||
| ```js | ||
| import {config} from '@bedrock/core'; | ||
|
|
||
|
|
@@ -86,26 +86,21 @@ connectOptions.authSource = 'my_provider_auth_db'; | |
| ``` | ||
| 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'; | ||
| ``` | ||
|
|
||
| ## Requirements | ||
|
|
||
| * Linux or Mac OS X (also works on Windows with some coaxing) | ||
| * node.js >= 14.x | ||
| * npm >= 6.x | ||
| * mongodb ~= 4.x | ||
| * node.js >= 20.x | ||
| * npm >= 10.x | ||
| * mongodb >= 6.x | ||
| * libkrb5-dev >= 1.x.x | ||
|
|
||
| ## Setup | ||
|
|
||
| 1. Ensure an admin user is set up on mongodb. To do so, follow the instructions | ||
| at [mongodb.org](http://docs.mongodb.org/manual/tutorial/add-user-administrator/) | ||
| for your version of MongoDB. Version 4.2.x is currently supported. | ||
| for your version of MongoDB. Version 6.x is currently supported. | ||
| 2. [optional] Tweak your project's configuration settings; see | ||
| [Configuration](#configuration) or [Quick Examples](#quickexamples). | ||
| [Configuration](#configuration) or [Quick Examples](#quick-examples). | ||
|
|
||
| ## API | ||
|
|
||
|
|
@@ -122,7 +117,7 @@ an error occurs, the returned promise rejects. If no error occurs, then once | |
| the promise resolves, the `collections` object will have keys that match the | ||
| collection names and values that are instances of | ||
| [mongodb-native][] | ||
| [Collection](http://mongodb.github.io/node-mongodb-native/2.0/api/Collection.html). | ||
| [Collection](https://mongodb.github.io/node-mongodb-native/6.14/classes/Collection.html). | ||
|
|
||
| ### createGridFSBucket(options) | ||
|
|
||
|
|
@@ -165,4 +160,4 @@ Commercial licensing and support are available by contacting | |
| [Digital Bazaar](https://digitalbazaar.com/) <[email protected]>. | ||
|
|
||
| [bedrock]: https://github.com/digitalbazaar/bedrock | ||
| [mongodb-native]: http://mongodb.github.io/node-mongodb-native/3.5/ | ||
| [mongodb-native]: https://www.mongodb.com/docs/drivers/node/current/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| /*! | ||
| * Copyright 2012 - 2024 Digital Bazaar, Inc. | ||
| * Copyright 2012 - 2025 Digital Bazaar, Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
|
|
@@ -15,7 +15,6 @@ | |
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import {config} from '@bedrock/core'; | ||
|
|
||
| config.mongodb = {}; | ||
|
|
@@ -54,12 +53,9 @@ config.mongodb.authentication = { | |
| }; | ||
| // this is used when making connections to the database | ||
| config.mongodb.connectOptions = { | ||
| useUnifiedTopology: true, | ||
| serverSelectionTimeoutMS: 30000, | ||
| autoReconnect: false, | ||
| useNewUrlParser: true, | ||
| // promotes binary BSON values to native Node.js buffers | ||
| promoteBuffers: true, | ||
| serverSelectionTimeoutMS: 30000 | ||
| // it is recommended to set either ssl or tls to true in production | ||
| // ssl: true | ||
| // tls: true | ||
|
|
@@ -79,7 +75,7 @@ config.mongodb.writeOptions = { | |
|
|
||
| config.mongodb.requirements = {}; | ||
| // server version requirement with server-style string | ||
| config.mongodb.requirements.serverVersion = '>=4.2'; | ||
| config.mongodb.requirements.serverVersion = '>=5'; | ||
|
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. The docs and tests are using v6. Is there a reason to have this lower?
Member
Author
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. Yes, there is software out there still using 5 for which this works -- we can bump it further in the future to avoid additional blockers on getting this update through. |
||
|
|
||
| // this is used by _createUser to add a user as an admin to a collection | ||
| // config.mongodb.collection = 'admin-collection'; | ||
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.
@BigBlueHat I recall the license tooling added these blank lines? Do they need to be preserved?
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.
No, in fact, the licensing tool should not be inserting them.
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.
I don't think it was a choice, similar to the extra spaces in the copyright date range. I was wondering if some part of that tooling would be grumpy if blank lines are gone.