Skip to content

Commit

Permalink
fix(update): cast right hand side of $pull as a query instead of an…
Browse files Browse the repository at this point in the history
… update for document arrays

Fix #8166
  • Loading branch information
vkarpov15 committed Sep 25, 2019
1 parent 9d455ad commit c371500
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/helpers/query/castUpdate.js
Expand Up @@ -4,6 +4,7 @@ const CastError = require('../../error/cast');
const StrictModeError = require('../../error/strict');
const ValidationError = require('../../error/validation');
const castNumber = require('../../cast/number');
const cast = require('../../cast');
const getEmbeddedDiscriminatorPath = require('./getEmbeddedDiscriminatorPath');
const handleImmutable = require('./handleImmutable');
const utils = require('../../utils');
Expand Down Expand Up @@ -139,6 +140,17 @@ function walkUpdatePath(schema, obj, op, options, context, filter, pref) {
key = keys[i];
val = obj[key];

// `$pull` is special because we need to cast the RHS as a query, not as
// an update.
if (op === '$pull') {
schematype = schema._getSchema(prefix + key);
if (schematype != null && schematype.schema != null) {
obj[key] = cast(schematype.schema, obj[key], options, context);
hasKeys = true;
continue;
}
}

if (val && val.constructor.name === 'Object') {
// watch for embedded doc schemas
schematype = schema._getSchema(prefix + key);
Expand Down

0 comments on commit c371500

Please sign in to comment.