Skip to content

Commit fd85337

Browse files
committed
docs(README): update examples to be more up-to-date
fixes #819
1 parent 4a5eacc commit fd85337

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

README.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ await mongod.stop();
113113

114114
### Available options for MongoMemoryServer
115115

116-
All options are optional.
116+
All options with `?` are optional, some options upon specified are required.
117117

118118
```js
119119
const mongod = new MongoMemoryServer({
@@ -125,6 +125,7 @@ const mongod = new MongoMemoryServer({
125125
storageEngine?: string, // by default `ephemeralForTest`(unless mongodb 7.0.0, where its `wiredTiger`), available engines: [ 'ephemeralForTest', 'wiredTiger' ]
126126
replSet?: string, // by default no replica set, replica set name
127127
args?: string[], // by default no additional arguments, any additional command line arguments for `mongod` `mongod` (ex. ['--notablescan'])
128+
auth?: boolean, // add "--auth" argument, dont use this directly use top-level "auth"
128129
},
129130
binary?: {
130131
version?: string, // by default '6.0.9'
@@ -136,18 +137,19 @@ const mongod = new MongoMemoryServer({
136137
},
137138
// using "auth" will manage "instance.auth"
138139
auth?: {
139-
disable?: boolean, // disable automatic auth creation
140+
// enable needs to be set to "true", otherwise automatic user creation is by default disabled
141+
enable?: boolean, // enable automatic user creation
140142
customRootName?: string, // by default "mongodb-memory-server-root"
141143
customRootPwd?: string, // by default "rootuser"
142144
force?: boolean, // force creation of users
143-
keyfileContent?: string, // by default "0123456789"
145+
keyfileContent?: string, // by default "0123456789" (only useful for replsets)
144146
extraUsers?: [{
145147
// see mongodb documentation https://docs.mongodb.com/manual/reference/method/db.createUser/#definition)
146148
createUser: string, // user name
147149
pwd: string, // user password
148150
roles: UserRoles[], // user roles
149151
database?: string, // which database the user is created on
150-
customData?: Record<string, any>,
152+
customData?: Record<string, any>, // any arbitrary information, see mongodb documentation
151153
mechanisms?: ('SCRAM-SHA-1' | 'SCRAM-SHA-256')[],
152154
authenticationRestrictions?: {
153155
clientSource?: string;
@@ -189,21 +191,20 @@ const replSet = new MongoMemoryReplSet({
189191
dbPath, // path to database files for this instance
190192
storageEngine, // same storage engine options
191193
},
192-
// each entry will result in a MongoMemoryServer (replSet.count will not count towards here)
194+
// each entry will result in a MongoMemoryServer (replSet.count will not limit the amount spawned by "instanceOpts")
193195
],
194196
// unless otherwise noted below these values will be in common with all instances spawned:
195197
replSet: {
196198
name, // replica set name (default: 'testset')
197199
auth?: boolean | AutomaticAuth, // enable auth, for options see #available-options-for-mongomemoryserver
198200
args, // any args specified here will be combined with any per instance args from `instanceOpts`
199201
count, // number of additional `mongod` processes to start (will not start any extra if instanceOpts.length > replSet.count); (default: 1)
200-
dbName, // default database for db URI strings. (default: uuid.v4())
202+
dbName, // default database for db URI strings
201203
ip, // by default '127.0.0.1', for binding to all IP addresses set it to `::,0.0.0.0`
202-
oplogSize, // size (in MB) for the oplog; (default: 1)
203204
spawn, // spawn options when creating the child processes
204205
storageEngine, // default storage engine for instance. (Can be overridden per instance)
205206
configSettings: {
206-
// Optional settings for replSetInitiate command. See https://docs.mongodb.com/manual/reference/command/replSetInitiate/
207+
// Optional settings for 'replSetInitiate' command. See https://docs.mongodb.com/manual/reference/command/replSetInitiate/
207208
chainingAllowed: boolean, // When true it allows secondary members to replicate from other secondary members. When false, secondaries can replicate only from the primary.
208209
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.
209210
heartbeatIntervalMillis: number, // The frequency in milliseconds of the heartbeats.
@@ -244,8 +245,6 @@ const mongoServer = await MongoMemoryServer.create();
244245
})();
245246
```
246247

247-
For additional information it is recommended to read this article [Testing a GraphQL Server using Jest with Mongoose](https://medium.com/entria/testing-a-graphql-server-using-jest-4e00d0e4980e)
248-
249248
### Test Runner Examples
250249

251250
[Documentation for Test Runner Integration Examples](https://nodkz.github.io/mongodb-memory-server/docs/guides/integration-examples/test-runners)

0 commit comments

Comments
 (0)