@@ -374,7 +374,15 @@ const methods = {
374
374
if ( val != null && utils . hasUserDefinedProperty ( val , '$each' ) ) {
375
375
atomics . $push = val ;
376
376
} else {
377
- atomics . $push . $each = atomics . $push . $each . concat ( val ) ;
377
+ if ( val . length === 1 ) {
378
+ atomics . $push . $each . push ( val [ 0 ] ) ;
379
+ } else if ( val . length < 10000 ) {
380
+ atomics . $push . $each . push ( ...val ) ;
381
+ } else {
382
+ for ( const v of val ) {
383
+ atomics . $push . $each . push ( v ) ;
384
+ }
385
+ }
378
386
}
379
387
} else {
380
388
atomics [ op ] = val ;
@@ -403,8 +411,7 @@ const methods = {
403
411
addToSet ( ) {
404
412
_checkManualPopulation ( this , arguments ) ;
405
413
406
- let values = [ ] . map . call ( arguments , this . _mapCast , this ) ;
407
- values = this [ arraySchemaSymbol ] . applySetters ( values , this [ arrayParentSymbol ] ) ;
414
+ const values = [ ] . map . call ( arguments , this . _mapCast , this ) ;
408
415
const added = [ ] ;
409
416
let type = '' ;
410
417
if ( values [ 0 ] instanceof ArraySubdocument ) {
@@ -415,7 +422,7 @@ const methods = {
415
422
type = 'ObjectId' ;
416
423
}
417
424
418
- const rawValues = utils . isMongooseArray ( values ) ? values . __array : this ;
425
+ const rawValues = utils . isMongooseArray ( values ) ? values . __array : values ;
419
426
const rawArray = utils . isMongooseArray ( this ) ? this . __array : this ;
420
427
421
428
rawValues . forEach ( function ( v ) {
@@ -682,10 +689,7 @@ const methods = {
682
689
683
690
_checkManualPopulation ( this , values ) ;
684
691
685
- const parent = this [ arrayParentSymbol ] ;
686
692
values = [ ] . map . call ( values , this . _mapCast , this ) ;
687
- values = this [ arraySchemaSymbol ] . applySetters ( values , parent , undefined ,
688
- undefined , { skipDocumentArrayCast : true } ) ;
689
693
let ret ;
690
694
const atomics = this [ arrayAtomicsSymbol ] ;
691
695
this . _markModified ( ) ;
@@ -711,7 +715,7 @@ const methods = {
711
715
'with different `$position`' ) ;
712
716
}
713
717
atomic = values ;
714
- ret = [ ] . push . apply ( arr , values ) ;
718
+ ret = _basePush . apply ( arr , values ) ;
715
719
}
716
720
717
721
this . _registerAtomic ( '$push' , atomic ) ;
@@ -917,7 +921,6 @@ const methods = {
917
921
values = arguments ;
918
922
} else {
919
923
values = [ ] . map . call ( arguments , this . _cast , this ) ;
920
- values = this [ arraySchemaSymbol ] . applySetters ( values , this [ arrayParentSymbol ] ) ;
921
924
}
922
925
923
926
const arr = utils . isMongooseArray ( this ) ? this . __array : this ;
0 commit comments