You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/migrating_to_8.md
+10Lines changed: 10 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -71,6 +71,16 @@ There's a few noteable changes in MongoDB Node driver v6 that affect Mongoose:
71
71
72
72
1. The `ObjectId` constructor no longer accepts strings of length 12. In Mongoose 7, `new mongoose.Types.ObjectId('12charstring')` was perfectly valid. In Mongoose 8, `new mongoose.Types.ObjectId('12charstring')` throws an error.
Copy file name to clipboardExpand all lines: docs/tutorials/ssl.md
+30-36Lines changed: 30 additions & 36 deletions
Original file line number
Diff line number
Diff line change
@@ -1,42 +1,40 @@
1
-
# SSL Connections
1
+
# TLS/SSL Connections
2
2
3
-
Mongoose supports connecting to [MongoDB clusters that require SSL connections](https://www.mongodb.com/docs/manual/tutorial/configure-ssl/). Setting the `ssl` option to `true` in [`mongoose.connect()`](../api/mongoose.html#mongoose_Mongoose-connect) or your connection string is enough to connect to a MongoDB cluster using SSL:
3
+
Mongoose supports connecting to [MongoDB clusters that require TLS/SSL connections](https://www.mongodb.com/docs/manual/tutorial/configure-ssl/). Setting the `tls` option to `true` in [`mongoose.connect()`](../api/mongoose.html#mongoose_Mongoose-connect) or your connection string is enough to connect to a MongoDB cluster using TLS/SSL:
The `ssl` option defaults to `false` for connection strings that start with `mongodb://`. However,
13
-
the `ssl` option defaults to `true` for connection strings that start with `mongodb+srv://`. So if you are using an srv connection string to connect to [MongoDB Atlas](https://www.mongodb.com/cloud/atlas), SSL is enabled by default.
12
+
The `tls` option defaults to `false` for connection strings that start with `mongodb://`. However,
13
+
the `tls` option defaults to `true` for connection strings that start with `mongodb+srv://`. So if you are using an srv connection string to connect to [MongoDB Atlas](https://www.mongodb.com/cloud/atlas), TLS/SSL is enabled by default.
14
14
15
-
If you try to connect to a MongoDB cluster that requires SSL without enabling the `ssl` option, `mongoose.connect()`
16
-
will error out with the below error:
15
+
If you try to connect to a MongoDB cluster that requires TLS/SSL without enabling the `tls`/`ssl` option, `mongoose.connect()` will error out with the below error:
17
16
18
17
```no-highlight
19
18
MongooseServerSelectionError: connection <monitor> to 127.0.0.1:27017 closed
20
19
at NativeConnection.Connection.openUri (/node_modules/mongoose/lib/connection.js:800:32)
21
20
...
22
21
```
23
22
24
-
## SSL Validation
23
+
## TLS/SSL Validation
25
24
26
-
By default, Mongoose validates the SSL certificate against a [certificate authority](https://en.wikipedia.org/wiki/Certificate_authority) to ensure the SSL certificate is valid. To disable this validation, set the `sslValidate` option
27
-
to `false`.
25
+
By default, Mongoose validates the TLS/SSL certificate against a [certificate authority](https://en.wikipedia.org/wiki/Certificate_authority) to ensure the TLS/SSL certificate is valid. To disable this validation, set the `tlsAllowInvalidCertificates` (or `tlsInsecure`) option to `true`.
In most cases, you should not disable SSL validation in production. However, `sslValidate: false` is often helpful
37
-
for debugging SSL connection issues. If you can connect to MongoDB with `sslValidate: false`, but not with
38
-
`sslValidate: true`, then you can confirm Mongoose can connect to the server and the server is configured to use
39
-
SSL correctly, but there's some issue with the SSL certificate.
34
+
In most cases, you should not disable TLS/SSL validation in production. However, `tlsAllowInvalidCertificates: true` is often helpful
35
+
for debugging SSL connection issues. If you can connect to MongoDB with `tlsAllowInvalidCertificates: true`, but not with
36
+
`tlsAllowInvalidCertificates: false`, then you can confirm Mongoose can connect to the server and the server is configured to use
37
+
TLS/SSL correctly, but there's some issue with the certificate.
40
38
41
39
For example, a common issue is the below error message:
42
40
@@ -45,17 +43,14 @@ MongooseServerSelectionError: unable to verify the first certificate
45
43
```
46
44
47
45
This error is often caused by [self-signed MongoDB certificates](https://medium.com/@rajanmaharjan/secure-your-mongodb-connections-ssl-tls-92e2addb3c89) or other situations where the certificate sent by the MongoDB
48
-
server is not registered with an established certificate authority. The solution is to set the `sslCA` option, which essentially sets a list of allowed SSL certificates.
46
+
server is not registered with an established certificate authority. The solution is to set the `tlsCAFile` option, which essentially sets a list of allowed SSL certificates.
// For example, see https://medium.com/@rajanmaharjan/secure-your-mongodb-connections-ssl-tls-92e2addb3c89
55
52
// for where the `rootCA.pem` file comes from.
56
-
// Please note that, in Mongoose >= 5.8.3, `sslCA` needs to be
57
-
// the **path to** the CA file, **not** the contents of the CA file
58
-
sslCA:`${__dirname}/rootCA.pem`
53
+
tlsCAFile:`${__dirname}/rootCA.pem`,
59
54
});
60
55
```
61
56
@@ -66,7 +61,7 @@ MongooseServerSelectionError: Hostname/IP does not match certificate's altnames:
66
61
```
67
62
68
63
The SSL certificate's [common name](https://knowledge.digicert.com/solution/SO7239.html)**must** line up with the host name
69
-
in your connection string. If the SSL certificate is for `hostname2.mydomain.com`, your connection string must connect to `hostname2.mydomain.com`, not any other hostname or IP address that may be equivalent to `hostname2.mydomain.com`. For replica sets, this also means that the SSL certificate's common name must line up with the [machine's `hostname`](../connections.html#replicaset-hostnames).
64
+
in your connection string. If the SSL certificate is for `hostname2.mydomain.com`, your connection string must connect to `hostname2.mydomain.com`, not any other hostname or IP address that may be equivalent to `hostname2.mydomain.com`. For replica sets, this also means that the SSL certificate's common name must line up with the [machine's `hostname`](../connections.html#replicaset-hostnames). To disable this validation, set the `tlsAllowInvalidHostnames` option to `true`.
70
65
71
66
## X.509 Authentication
72
67
@@ -76,39 +71,38 @@ If you're using [X.509 authentication](https://www.mongodb.com/docs/drivers/node
With MongoDB Atlas, X.509 certificates are not Root CA certificates and will not work with the `sslCA` parameter as self-signed certificates would. If the `sslCA` parameter is used an error similar to the following would be raised:
90
+
With MongoDB Atlas, X.509 certificates are not Root CA certificates and will not work with the `tlsCAFile` parameter as self-signed certificates would. If the `tlsCAFile` parameter is used an error similar to the following would be raised:
98
91
99
92
```no-highlight
100
93
MongoServerSelectionError: unable to get local issuer certificate
101
94
```
102
95
103
-
To connect to a MongoDB Atlas cluster using X.509 authentication the correct option to set is `tlsCertificateKeyFile`. The connection string already specifies the `authSource` and `authMechanism`, and the DNS `TXT` record would supply the parameter and value for `sslValidate`, however they're included below as `connect()` options for completeness:
96
+
To connect to a MongoDB Atlas cluster using X.509 authentication the correct option to set is `tlsCertificateKeyFile`. The connection string already specifies the `authSource` and `authMechanism`, however they're included below as `connect()` options for completeness:
0 commit comments