@@ -178,12 +178,56 @@ module.exports = function (dialect) {
178178 const modifierParts = [ ] ;
179179
180180 each ( modifier , ( value , key ) => {
181- const modifierPart =
182- dialect . wrapIdentifier ( key ) +
183- ' = ' +
184- dialect . buildBlock ( 'term' , { term : value , type : 'value' } ) ;
181+ // Handle MongoDB operators
182+ if ( key . startsWith ( '$' ) ) {
183+ switch ( key ) {
184+ case '$set' : {
185+ each ( value , ( setValue , setKey ) => {
186+ const modifierPart =
187+ dialect . wrapIdentifier ( setKey ) +
188+ ' = ' +
189+ dialect . buildBlock ( 'term' , { term : setValue , type : 'value' } ) ;
190+ modifierParts . push ( modifierPart ) ;
191+ } ) ;
192+
193+ break ;
194+ }
195+
196+ case '$inc' : {
197+ each ( value , ( incValue , incKey ) => {
198+ const modifierPart =
199+ dialect . wrapIdentifier ( incKey ) +
200+ ' = ' +
201+ dialect . wrapIdentifier ( incKey ) +
202+ ' + ' +
203+ dialect . buildBlock ( 'term' , { term : incValue , type : 'value' } ) ;
204+ modifierParts . push ( modifierPart ) ;
205+ } ) ;
206+
207+ break ;
208+ }
209+
210+ case '$unset' : {
211+ each ( value , ( unsetValue , unsetKey ) => {
212+ const modifierPart = dialect . wrapIdentifier ( unsetKey ) + ' = NULL' ;
213+ modifierParts . push ( modifierPart ) ;
214+ } ) ;
185215
186- modifierParts . push ( modifierPart ) ;
216+ break ;
217+ }
218+
219+ default : {
220+ throw new Error ( 'Unknown MongoDB operator "' + key + '"' ) ;
221+ }
222+ }
223+ } else {
224+ // Handle regular field assignments
225+ const modifierPart =
226+ dialect . wrapIdentifier ( key ) +
227+ ' = ' +
228+ dialect . buildBlock ( 'term' , { term : value , type : 'value' } ) ;
229+ modifierParts . push ( modifierPart ) ;
230+ }
187231 } ) ;
188232
189233 return 'set ' + modifierParts . join ( ', ' ) ;
@@ -681,6 +725,11 @@ module.exports = function (dialect) {
681725 throw new TypeError ( 'Invalid term object' ) ;
682726 }
683727
728+ // Handle expression objects
729+ if ( has ( term , 'expression' ) ) {
730+ return dialect . buildExpression ( term . expression ) ;
731+ }
732+
684733 if ( has ( term , 'name' ) ) {
685734 let field = '' ;
686735
@@ -716,6 +765,11 @@ module.exports = function (dialect) {
716765 throw new TypeError ( 'Invalid term object' ) ;
717766 }
718767
768+ // Handle expression objects
769+ if ( has ( term , 'expression' ) ) {
770+ return dialect . buildExpression ( term . expression ) ;
771+ }
772+
719773 if ( objectUtils . hasSome ( term , termKeys ) ) {
720774 const termKey = keys ( term ) [ 0 ] ;
721775 const termValue = term [ termKey ] ;
0 commit comments