Skip to content

Commit f57ac28

Browse files
committed
docs(common-issues): add file
1 parent f42c452 commit f57ac28

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

docs/guides/common-issues.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
id: common-issues
3+
title: 'Common Issues'
4+
---
5+
6+
There are some common issues you may encounter with mongodb-memory-server (or also manually handling mongod instances), this guide will try to explain why they happen how to fix those issues.
7+
8+
## MongoWriteConcernError: operation was interrupted
9+
10+
The Error `MongoWriteConcernError: operation was interrupted` happens when a operation which is not retryable fails, which includes for example `db.dropDatabase`.
11+
This Error happens because mongodb firstly starts all instances, says they are okay and has a primary (which are all events mongodb-memory-server listens for before resolving `.start`), but the shortly after the `.start` is resolved, the instace that is primary decides to step-down due to whatever reason.
12+
13+
The fix is to manually re-try those operations, like:
14+
15+
```js
16+
// original:
17+
async function setup(db) {
18+
await db.dropDatabase();
19+
}
20+
21+
// fix
22+
async function setup(db) {
23+
let retries = 5;
24+
while (retries > 0) {
25+
retries -= 1;
26+
try {
27+
await _setup(db);
28+
} catch (err) {
29+
if (err instanceof mongodb.MongoWriteConcernError && /operation was interrupted/.test(err.message)) {
30+
continue;
31+
}
32+
33+
throw err;
34+
}
35+
}
36+
}
37+
38+
async function _setup(db) {
39+
await db.dropDatabase();
40+
}
41+
```
42+
43+
See [Operations which are retry-able](https://www.mongodb.com/docs/manual/core/retryable-writes/#retryable-write-operations).

website/sidebars.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ module.exports = {
3838
'guides/known-issues',
3939
'guides/error-warning-details',
4040
'guides/mongodb-server-versions',
41+
'guides/common-issues',
4142
],
4243
Migration: ['guides/migration/migrate8', 'guides/migration/migrate7'],
4344
},

0 commit comments

Comments
 (0)