@@ -14,6 +14,24 @@ const schemaMixedSymbol = require('../../schema/symbols').schemaMixedSymbol;
1414const setDottedPath = require ( '../path/setDottedPath' ) ;
1515const utils = require ( '../../utils' ) ;
1616
17+ const mongodbUpdateOperators = new Set ( [
18+ '$currentDate' ,
19+ '$inc' ,
20+ '$min' ,
21+ '$max' ,
22+ '$mul' ,
23+ '$rename' ,
24+ '$set' ,
25+ '$setOnInsert' ,
26+ '$unset' ,
27+ '$addToSet' ,
28+ '$pop' ,
29+ '$pull' ,
30+ '$push' ,
31+ '$pullAll' ,
32+ '$bit'
33+ ] ) ;
34+
1735/**
1836 * Casts an update op based on the given schema
1937 *
@@ -58,7 +76,7 @@ module.exports = function castUpdate(schema, obj, options, context, filter) {
5876 while ( i -- ) {
5977 const op = ops [ i ] ;
6078 // if overwrite is set, don't do any of the special $set stuff
61- if ( op [ 0 ] !== '$' && ! overwrite ) {
79+ if ( ! mongodbUpdateOperators . has ( op ) && ! overwrite ) {
6280 // fix up $set sugar
6381 if ( ! ret . $set ) {
6482 if ( obj . $set ) {
@@ -88,7 +106,7 @@ module.exports = function castUpdate(schema, obj, options, context, filter) {
88106 if ( val &&
89107 typeof val === 'object' &&
90108 ! Buffer . isBuffer ( val ) &&
91- ( ! overwrite || hasDollarKey ) ) {
109+ ( ! overwrite || mongodbUpdateOperators . has ( op ) ) ) {
92110 walkUpdatePath ( schema , val , op , options , context , filter ) ;
93111 } else if ( overwrite && ret && typeof ret === 'object' ) {
94112 walkUpdatePath ( schema , ret , '$set' , options , context , filter ) ;
@@ -540,7 +558,7 @@ function castUpdateVal(schema, val, op, $conditional, context, path) {
540558 return Boolean ( val ) ;
541559 }
542560
543- if ( / ^ \$ / . test ( $conditional ) ) {
561+ if ( mongodbUpdateOperators . has ( $conditional ) ) {
544562 return schema . castForQuery (
545563 $conditional ,
546564 val ,
0 commit comments