Skip to content

Commit

Permalink
docs(readme): Update options according to mongoose@4.11.3 and above
Browse files Browse the repository at this point in the history
Related #16
  • Loading branch information
nodkz committed Aug 24, 2017
1 parent 3e1a25c commit 99e3883
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,11 @@ const mongoServer = new MongodbMemoryServer();

mongoose.Promise = Promise;
mongoServer.getConnectionString().then((mongoUri) => {
const mongooseOpts = {
server: {
auto_reconnect: true,
reconnectTries: Number.MAX_VALUE,
reconnectInterval: 1000,
},
const mongooseOpts = { // options for mongoose 4.11.3 and above
autoReconnect: true,
reconnectTries: Number.MAX_VALUE,
reconnectInterval: 1000,
useMongoClient: true,
};

mongoose.connect(mongoUri, mongooseOpts);
Expand Down Expand Up @@ -117,13 +116,12 @@ const connections = {
conn3: mongoose.createConnection(),
};

const mongooseOpts = {
server: {
promiseLibrary = Promise;
auto_reconnect: true,
reconnectTries: Number.MAX_VALUE,
reconnectInterval: 1000,
},
const mongooseOpts = { // options for mongoose 4.11.3 and above
promiseLibrary = Promise;
autoReconnect: true,
reconnectTries: Number.MAX_VALUE,
reconnectInterval: 1000,
useMongoClient: true,
};

mongoServer1.getConnectionString('server1_db1').then((mongoUri) => {
Expand Down Expand Up @@ -174,6 +172,7 @@ Note: When you create mongoose connection manually, you should do:
```js
import mongoose from 'mongoose';

const opts = { useMongoClient: true };
const conn = mongoose.createConnection(); // just create connection instance
const User = conn.model('User', new mongoose.Schema({ name: String })); // define model
conn.open(uri, opts); // open connection to database (NOT `connect` method!)
Expand All @@ -182,6 +181,7 @@ With default connection:
```js
import mongoose from 'mongoose';

const opts = { useMongoClient: true };
mongoose.connect(uri, opts);
const User = mongoose.model('User', new mongoose.Schema({ name: String })); // define model
```
Expand All @@ -197,11 +197,12 @@ import mongoose from 'mongoose';
import MongodbMemoryServer from 'mongodb-memory-server';

let mongoServer;
const opts = { useMongoClient: true };

before((done) => {
mongoServer = new MongodbMemoryServer();
mongoServer.getConnectionString().then((mongoUri) => {
mongoose.connect(mongoUri, (err) => {
mongoose.connect(mongoUri, opts, (err) => {
done(err);
});
});
Expand Down Expand Up @@ -230,11 +231,12 @@ import MongodbMemoryServer from 'mongodb-memory-server';
jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000;

let mongoServer;
const opts = { useMongoClient: true };

beforeAll(async () => {
mongoServer = new MongodbMemoryServer();
const mongoUri = await mongoServer.getConnectionString();
mongoose.connect(mongoUri, (err) => {
mongoose.connect(mongoUri, opts, (err) => {
console.error(err);
});
});
Expand Down

0 comments on commit 99e3883

Please sign in to comment.