Skip to content

Commit

Permalink
fix(mongoose): support passing options object to Mongoose constructor
Browse files Browse the repository at this point in the history
Fix #8144
  • Loading branch information
vkarpov15 committed Sep 12, 2019
1 parent 293319b commit 691aabb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,22 @@ require('./helpers/printJestWarning');
* const m = new mongoose.Mongoose();
*
* @api public
* @param {Object} options see [`Mongoose#set()` docs](/docs/api/mongoose.html#mongoose_Mongoose-set)
*/
function Mongoose(options) {
this.connections = [];
this.models = {};
this.modelSchemas = {};
// default global options
this.options = {
this.options = Object.assign({
pluralization: true
};
}, options);
const conn = this.createConnection(); // default connection
conn.models = this.models;

this._pluralize = legacyPluralize;
if (this.options.pluralization) {
this._pluralize = legacyPluralize;
}

// If a user creates their own Mongoose instance, give them a separate copy
// of the `Schema` constructor so they get separate custom types. (gh-6933)
Expand Down
6 changes: 6 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ describe('mongoose module:', function() {
done();
});

it('options object (gh-8144)', function() {
const mongoose = new Mongoose({ bufferCommands: false });

assert.strictEqual(mongoose.options.bufferCommands, false);
});

it('bufferCommands option (gh-5879)', function(done) {
const mongoose = new Mongoose();

Expand Down

0 comments on commit 691aabb

Please # to comment.