Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
niftylettuce opened this issue Sep 9, 2019 · 1 comment
Closed

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

niftylettuce opened this issue Sep 9, 2019 · 1 comment
Milestone

Comments

@niftylettuce
Copy link
Contributor

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;

@vkarpov15 vkarpov15 added this to the 5.7.1 milestone Sep 10, 2019
@niftylettuce
Copy link
Contributor Author

ty!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants