Skip to content

Commit

Permalink
fix(mongoose): allow setting autoCreate as a global option to be co…
Browse files Browse the repository at this point in the history
…nsistent with `autoIndex`

Fix #9466
  • Loading branch information
vkarpov15 committed Oct 6, 2020
1 parent 690bacb commit 0335578
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ Mongoose.prototype.driver = require('./driver');
* - 'typePojoToMixed': true by default, may be `false` or `true`. Sets the default typePojoToMixed for schemas.
* - 'maxTimeMS': If set, attaches [maxTimeMS](https://docs.mongodb.com/manual/reference/operator/meta/maxTimeMS/) to every query
* - 'autoIndex': true by default. Set to false to disable automatic index creation for all models associated with this Mongoose instance.
* - 'autoCreate': Set to `true` to make Mongoose call [`Model.createCollection()`](/docs/api/model.html#model_Model.createCollection) automatically when you create a model with `mongoose.model()` or `conn.model()`. This is useful for testing transactions, change streams, and other features that require the collection to exist.
*
* @param {String} key
* @param {String|Function|Boolean} value
Expand Down
5 changes: 2 additions & 3 deletions lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -1236,9 +1236,8 @@ Model.init = function init(callback) {
const Promise = PromiseProvider.get();
const autoIndex = utils.getOption('autoIndex',
this.schema.options, this.db.config, this.db.base.options);
const autoCreate = this.schema.options.autoCreate == null ?
this.db.config.autoCreate :
this.schema.options.autoCreate;
const autoCreate = utils.getOption('autoCreate',
this.schema.options, this.db.config, this.db.base.options);

const _ensureIndexes = autoIndex ?
cb => this.ensureIndexes({ _automatic: true }, cb) :
Expand Down
1 change: 1 addition & 0 deletions lib/validoptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
const VALID_OPTIONS = Object.freeze([
'applyPluginsToChildSchemas',
'applyPluginsToDiscriminators',
'autoCreate',
'autoIndex',
'bufferCommands',
'cloneSchemas',
Expand Down

0 comments on commit 0335578

Please sign in to comment.