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: README.md
+25Lines changed: 25 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -146,10 +146,35 @@ const replSet = new MongoMemoryReplSet({
146
146
oplogSize, // size (in MB) for the oplog; (default: 1)
147
147
spawn, // spawn options when creating the child processes
148
148
storageEngine, // default storage engine for instance. (Can be overridden per instance)
149
+
configSettings: { // Optional settings for replSetInitiate command. See https://docs.mongodb.com/manual/reference/command/replSetInitiate/
150
+
chainingAllowed: boolean, // When true it allows secondary members to replicate from other secondary members. When false, secondaries can replicate only from the primary.
151
+
heartbeatTimeoutSecs: number, // Number of seconds that the replica set members wait for a successful heartbeat from each other. If a member does not respond in time, other members mark the delinquent member as inaccessible.
152
+
heartbeatIntervalMillis: number, // The frequency in milliseconds of the heartbeats.
153
+
electionTimeoutMillis: number, // The time limit in milliseconds for detecting when a replica set’s primary is unreachable.
154
+
catchUpTimeoutMillis: number, // Time limit for a newly elected primary to sync (catch up) with the other replica set members that may have more recent writes.
155
+
}
149
156
},
150
157
});
151
158
```
152
159
160
+
The `replSet.configSettings` can be used to tune the initialization of the replica set. By default one of the nodes has
161
+
to be promoted to Primary before the replica set can be successfully used but that happens only after a timeout of 10 seconds
162
+
(see [electionTimeoutMillis](https://docs.mongodb.com/manual/reference/replica-configuration/#rsconf.settings.electionTimeoutMillis)).
163
+
164
+
It is possible to force the replica set to elect a node as Primary before the default 10 seconds by changing the `electionTimeoutMillis`
165
+
parameter as shown below:
166
+
167
+
```js
168
+
constreplSet=newMongoMemoryReplSet({
169
+
replSet: {
170
+
configSettings: {
171
+
electionTimeoutMillis:100,
172
+
},
173
+
},
174
+
})
175
+
awaitreplSet.waitUntilRunning()
176
+
```
177
+
153
178
### Simple test with MongoClient
154
179
155
180
Take a look at this [test file](https://github.com/nodkz/mongodb-memory-server/blob/master/src/__tests__/singleDB-test.ts).
0 commit comments