Skip to content

Commit

Permalink
fix: allow calling create() after bulkWrite() by clearing interna…
Browse files Browse the repository at this point in the history
…l casting context

Fix #9350
  • Loading branch information
vkarpov15 committed Aug 23, 2020
1 parent 56fb748 commit 0bdac75
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
5 changes: 4 additions & 1 deletion lib/schema/boolean.js
Expand Up @@ -230,7 +230,10 @@ SchemaBoolean.prototype.castForQuery = function($conditional, val) {
*/

SchemaBoolean.prototype._castNullish = function _castNullish(v) {
if (typeof v === 'undefined' && this.$$context != null && this.$$context._mongooseOptions.omitUndefined) {
if (typeof v === 'undefined' &&
this.$$context != null &&
this.$$context._mongooseOptions != null &&
this.$$context._mongooseOptions.omitUndefined) {
return v;
}
const castBoolean = typeof this.constructor.cast === 'function' ?
Expand Down
13 changes: 10 additions & 3 deletions lib/schematype.js
Expand Up @@ -1461,12 +1461,19 @@ SchemaType.prototype.$conditionalHandlers = {
SchemaType.prototype.castForQueryWrapper = function(params) {
this.$$context = params.context;
if ('$conditional' in params) {
return this.castForQuery(params.$conditional, params.val);
const ret = this.castForQuery(params.$conditional, params.val);
this.$$context = null;
return ret;
}
if (params.$skipQueryCastForUpdate || params.$applySetters) {
return this._castForQuery(params.val);
const ret = this._castForQuery(params.val);
this.$$context = null;
return ret;
}
return this.castForQuery(params.val);

const ret = this.castForQuery(params.val);
this.$$context = null;
return ret;
};

/**
Expand Down

0 comments on commit 0bdac75

Please sign in to comment.