Skip to content

Commit 068f584

Browse files
committed
docs(faq): add question about localhost being slow if no IPv6
Fix #6784
1 parent 25196b2 commit 068f584

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

docs/faq.jade

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -352,10 +352,10 @@ block content
352352
doc.createdAt = new Date(2011, 5, 1).setHours(4);
353353
doc.save(); // Works
354354
```
355-
355+
356356
<hr id="parallel_saves" />
357-
358-
**Q**. Why does calling `save()` multiple times on the same document in parallel only let
357+
358+
**Q**. Why does calling `save()` multiple times on the same document in parallel only let
359359
the first save call succeed and return ParallelSaveErrors for the rest?
360360

361361
**A**. Due to the asynchronous nature of validation and middleware in general, calling
@@ -366,11 +366,25 @@ block content
366366

367367
**Q**. Why is **any** 12 character string successfully cast to an ObjectId?
368368

369-
**A**. Technically, any 12 character string is a valid [ObjectId](https://docs.mongodb.com/manual/reference/bson-types/#objectid).
369+
**A**. Technically, any 12 character string is a valid [ObjectId](https://docs.mongodb.com/manual/reference/bson-types/#objectid).
370370
Consider using a regex like `/^[a-f0-9]{24}$/` to test whether a string is exactly 24 hex characters.
371371

372+
<hr id="slow-localhost" />
373+
374+
**Q**. I'm connecting to `localhost` and it takes me nearly 1 second to connect. How do I fix this?
375+
376+
**A**. The underlying MongoDB driver defaults to looking for IPv6 addresses, so the most likely cause is that your `localhost` DNS mapping isn't configured to handle IPv6. Use `127.0.0.1` instead of `localhost` or use the `family` option as shown in the [connection docs](https://mongoosejs.com/docs/connections.html#options).
377+
378+
```javascript
379+
// One alternative is to bypass 'localhost'
380+
mongoose.connect('mongodb://127.0.0.1:27017/test');
381+
// Another option is to specify the `family` option, which tells the
382+
// MongoDB driver to only look for IPv4 addresses rather than IPv6 first.
383+
mongoose.connect('mongodb://localhost:27017/test', { family: 4 });
384+
```
385+
372386
<hr id="add_something" />
373-
387+
374388
**Something to add?**
375389

376390
If you'd like to contribute to this page, please

0 commit comments

Comments
 (0)