@@ -66,6 +66,10 @@ const mongod = new MongodbMemoryServer({
66
66
});
67
67
` ` `
68
68
69
+ ### Simple test with MongoClient
70
+
71
+ Take a look at this [test file](https://github.com/nodkz/mongodb-memory-server/blob/master/src/__tests__/singleDB-test.js).
72
+
69
73
### Provide connection string to mongoose
70
74
` ` ` js
71
75
import mongoose from ' mongoose' ;
@@ -79,7 +83,7 @@ mongoServer.getConnectionString().then((mongoUri) => {
79
83
autoReconnect: true ,
80
84
reconnectTries: Number .MAX_VALUE ,
81
85
reconnectInterval: 1000 ,
82
- useMongoClient: true ,
86
+ useMongoClient: true , // remove this line if you use mongoose 5 and above
83
87
};
84
88
85
89
mongoose .connect (mongoUri, mongooseOpts);
@@ -123,7 +127,7 @@ const mongooseOpts = { // options for mongoose 4.11.3 and above
123
127
autoReconnect: true ,
124
128
reconnectTries: Number .MAX_VALUE ,
125
129
reconnectInterval: 1000 ,
126
- useMongoClient: true ,
130
+ useMongoClient: true , // remove this line if you use mongoose 5 and above
127
131
};
128
132
129
133
mongoServer1 .getConnectionString (' server1_db1' ).then ((mongoUri ) => {
@@ -174,7 +178,7 @@ Note: When you create mongoose connection manually, you should do:
174
178
` ` ` js
175
179
import mongoose from ' mongoose' ;
176
180
177
- const opts = { useMongoClient: true };
181
+ const opts = { useMongoClient: true }; // remove this option if you use mongoose 5 and above
178
182
const conn = mongoose .createConnection (); // just create connection instance
179
183
const User = conn .model (' User' , new mongoose.Schema ({ name: String })); // define model
180
184
conn .open (uri, opts); // open connection to database (NOT `connect` method!)
@@ -183,7 +187,7 @@ With default connection:
183
187
` ` ` js
184
188
import mongoose from ' mongoose' ;
185
189
186
- const opts = { useMongoClient: true };
190
+ const opts = { useMongoClient: true }; // remove this option if you use mongoose 5 and above
187
191
mongoose .connect (uri, opts);
188
192
const User = mongoose .model (' User' , new mongoose.Schema ({ name: String })); // define model
189
193
` ` `
@@ -199,7 +203,7 @@ import mongoose from 'mongoose';
199
203
import MongodbMemoryServer from ' mongodb-memory-server' ;
200
204
201
205
let mongoServer;
202
- const opts = { useMongoClient: true };
206
+ const opts = { useMongoClient: true }; // remove this option if you use mongoose 5 and above
203
207
204
208
before ((done ) => {
205
209
mongoServer = new MongodbMemoryServer ();
@@ -233,7 +237,7 @@ import MongodbMemoryServer from 'mongodb-memory-server';
233
237
jasmine .DEFAULT_TIMEOUT_INTERVAL = 60000 ;
234
238
235
239
let mongoServer;
236
- const opts = { useMongoClient: true };
240
+ const opts = { useMongoClient: true }; // remove this option if you use mongoose 5 and above
237
241
238
242
beforeAll (async () => {
239
243
mongoServer = new MongodbMemoryServer ();
0 commit comments