Skip to content

Commit e9c6ce5

Browse files
arodrigesnodkz
authored andcommitted
docs: improve ReplicaSet example with mongoose code
1 parent 53486cf commit e9c6ce5

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

README.md

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,26 @@ Environment variables have higher priority than contents of package.json.
164164
```js
165165
import { MongoMemoryReplSet } from 'mongodb-memory-server';
166166

167-
const replSet = new MongoMemoryReplSet();
167+
const replSet = new MongoMemoryReplSet({
168+
debug: false,
169+
replSet: { storageEngine: 'wiredTiger' },
170+
});
168171
await replSet.waitUntilRunning();
169172
const uri = await mongod.getConnectionString();
170-
const port = await mongod.getPort();
171-
const dbPath = await mongod.getDbPath();
172-
const dbName = await mongod.getDbName();
173-
174-
// some code
173+
// or you may obtain the connection config parts:
174+
// const port = await mongod.getPort();
175+
// const dbPath = await mongod.getDbPath();
176+
// const dbName = await mongod.getDbName();
177+
178+
// some code, eg. for mongoose
179+
mongoose.set('useFindAndModify', false);
180+
mongoose.set('useCreateIndex', true);
181+
mongoose.connect(uri, {
182+
useNewUrlParser: true,
183+
useUnifiedTopology: true,
184+
});
185+
// after some useful code don't forget to disconnect
186+
mongoose.disconnect();
175187

176188
// stop replica set manually
177189
replSet.stop();

0 commit comments

Comments
 (0)