From 40c5c60f63f742faac2873842e75501f2dcec7c0 Mon Sep 17 00:00:00 2001 From: filipenevola Date: Sun, 22 Mar 2020 17:41:39 -0400 Subject: [PATCH 1/3] Doc: Adds support to override mongo options via Meteor settings --- source/api/collections.md | 58 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/source/api/collections.md b/source/api/collections.md index 78d25eee13..8d7ba674c4 100644 --- a/source/api/collections.md +++ b/source/api/collections.md @@ -923,3 +923,61 @@ the detail can differ depending on how you host your MongoDB. Read more [here](h > As of Meteor 1.4, you must ensure you set the `replicaSet` parameter on your `METEOR_OPLOG_URL` + +

Mongo Connection Options

+ +MongoDB provides many connection options, usually the default works but in some +cases you may want to pass additional options. You can do it in two ways: + +

Meteor settings

+ +You can use your Meteor settings file to set the options in a property called +`overrideMongoOptions`, these values will be provided as options for MongoDB in +the connect method. + +> this option was introduced in Meteor 1.10.2 + +For example, you may want to specify a certificate for your +TLS connection ([see the options here](https://mongodb.github.io/node-mongodb-native/3.5/tutorials/connect/tls/)) then you could use these options: +```json + "overrideMongoOptions": { + "tls": true, + "tlsCAFileAsset": "certificate.pem" + } +``` +Meteor will convert relative paths to absolute paths if the option name (key) +ends with `Asset`, for this to work properly you need to place the files in the + `private` in the root of your project. In the example Mongo connection would + receive this: +```json + "overrideMongoOptions": { + "tls": true, + "tlsCAFile": "/absolute/path/certificate.pem" + } +``` +See that the final option name (key) does not contain `Asset` in the end as +expected by MongoDB. + +This configuration is necessary in some MongoDB host providers to avoid this +error `MongoNetworkError: failed to connect to server [sg-meteorappdb-32194.servers.mongodirector.com:27017] on first connect [Error: self signed certificate +`. + +Another way to avoid this error is to allow invalid certificates with this +option: +```json + "overrideMongoOptions": { + "tlsAllowInvalidCertificates": true + } +``` + +You can pass any MongoDB valid option, these are just examples using +certificates configurations. + +

Mongo.setConnectionOptions

+ +You can also call `Mongo.setConnectionOptions` to set the connection options but +you need to call it before any other package using Mongo connections is +initialized so you need to add this code in a package and add it above the other +packages, like accounts-base in your `.meteor/packages` file. + +> this option was introduced in Meteor 1.4 From 140b71ab23cbe965c67d709bc77be11ab610ac94 Mon Sep 17 00:00:00 2001 From: filipenevola Date: Thu, 2 Apr 2020 10:24:28 -0400 Subject: [PATCH 2/3] Doc: Adds support to override mongo options via Meteor settings --- source/api/collections.md | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/source/api/collections.md b/source/api/collections.md index 8d7ba674c4..4a0c8d2355 100644 --- a/source/api/collections.md +++ b/source/api/collections.md @@ -940,9 +940,13 @@ the connect method. For example, you may want to specify a certificate for your TLS connection ([see the options here](https://mongodb.github.io/node-mongodb-native/3.5/tutorials/connect/tls/)) then you could use these options: ```json - "overrideMongoOptions": { - "tls": true, - "tlsCAFileAsset": "certificate.pem" + "packages": { + "mongo": { + "options": { + "tls": true, + "tlsCAFileAsset": "certificate.pem" + } + } } ``` Meteor will convert relative paths to absolute paths if the option name (key) @@ -950,9 +954,13 @@ ends with `Asset`, for this to work properly you need to place the files in the `private` in the root of your project. In the example Mongo connection would receive this: ```json - "overrideMongoOptions": { - "tls": true, - "tlsCAFile": "/absolute/path/certificate.pem" + "packages": { + "mongo": { + "options": { + "tls": true, + "tlsCAFile": "/absolute/path/certificate.pem" + } + } } ``` See that the final option name (key) does not contain `Asset` in the end as @@ -965,8 +973,12 @@ error `MongoNetworkError: failed to connect to server [sg-meteorappdb-32194.serv Another way to avoid this error is to allow invalid certificates with this option: ```json - "overrideMongoOptions": { - "tlsAllowInvalidCertificates": true + "packages": { + "mongo": { + "options": { + "tlsAllowInvalidCertificates": true + } + } } ``` From ef1d7e9ef98369e8393e5d7526b47d45978d00bb Mon Sep 17 00:00:00 2001 From: filipenevola Date: Thu, 2 Apr 2020 10:36:12 -0400 Subject: [PATCH 3/3] Doc: Adds support to override mongo options via Meteor settings --- source/api/collections.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/api/collections.md b/source/api/collections.md index 4a0c8d2355..d39e101d91 100644 --- a/source/api/collections.md +++ b/source/api/collections.md @@ -932,7 +932,7 @@ cases you may want to pass additional options. You can do it in two ways:

Meteor settings

You can use your Meteor settings file to set the options in a property called -`overrideMongoOptions`, these values will be provided as options for MongoDB in +`options` inside `packages` > `mongo`, these values will be provided as options for MongoDB in the connect method. > this option was introduced in Meteor 1.10.2