Skip to content

Options passed to new mongoose.Mongoose instance are not used #8144

Closed
@niftylettuce

Description

@niftylettuce

For example, the logic here does not use options object passed to the constructor and therefore options cannot be configured on new instances without having to manually call .set('some', 'value);.

mongoose/lib/index.js

Lines 60 to 94 in 61f698c

function Mongoose(options) {
this.connections = [];
this.models = {};
this.modelSchemas = {};
// default global options
this.options = {
pluralization: true
};
const conn = this.createConnection(); // default connection
conn.models = this.models;
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)
if (!options || !options[defaultMongooseSymbol]) {
const _this = this;
this.Schema = function() {
this.base = _this;
return Schema.apply(this, arguments);
};
this.Schema.prototype = Object.create(Schema.prototype);
Object.assign(this.Schema, Schema);
this.Schema.base = this;
this.Schema.Types = Object.assign({}, Schema.Types);
} else {
// Hack to work around babel's strange behavior with
// `import mongoose, { Schema } from 'mongoose'`. Because `Schema` is not
// an own property of a Mongoose global, Schema will be undefined. See gh-5648
for (const key of ['Schema', 'model']) {
this[key] = Mongoose.prototype[key];
}
}
this.Schema.prototype.base = this;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions