Skip to content

Commit fe65746

Browse files
docs(NODE-4911): add dns connection issue notes to READ.ME (#3509)
Co-authored-by: Raj Bhattacharyya <[email protected]>
1 parent cc8ea1d commit fe65746

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,18 @@ Add code to connect to the server and the database **myProject**:
133133
> However, all async API calls support an optional callback as the final argument,
134134
> if a callback is provided a Promise will not be returned.
135135
136+
> **NOTE:** Resolving DNS Connection issues
137+
>
138+
> Node.js 18 changed the default DNS resolution ordering from always prioritizing ipv4 to the ordering
139+
> returned by the DNS provider. In some environments, this can result in `localhost` resolving to
140+
> an ipv6 address instead of ipv4 and a consequent failure to connect to the server.
141+
>
142+
> This can be resolved by:
143+
> - specifying the ip address family using the MongoClient `family` option (`MongoClient(<uri>, { family: 4 } )`)
144+
> - launching mongod or mongos with the ipv6 flag enabled ([--ipv6 mongod option documentation](https://www.mongodb.com/docs/manual/reference/program/mongod/#std-option-mongod.--ipv6))
145+
> - using a host of `127.0.0.1` in place of localhost
146+
> - specifying the DNS resolution ordering with the `--dns-resolution-order` Node.js command line argument (e.g. `node --dns-resolution-order=ipv4first`)
147+
136148
```js
137149
const { MongoClient } = require('mongodb');
138150
// or as an es module:

0 commit comments

Comments
 (0)