From 691aabbd4122cfec710fd208f0e3e1739dde9133 Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Thu, 12 Sep 2019 11:12:34 -0400 Subject: [PATCH] fix(mongoose): support passing options object to Mongoose constructor Fix #8144 --- lib/index.js | 9 ++++++--- test/index.test.js | 6 ++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/index.js b/lib/index.js index f2ac3678515..c76914492c7 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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) diff --git a/test/index.test.js b/test/index.test.js index 8e487e4eca4..e9e7eee8a01 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -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();