@@ -2536,6 +2536,48 @@ describe('model: update:', function() {
2536
2536
catch ( done ) ;
2537
2537
} ) ;
2538
2538
2539
+ it ( 'doesn\'t skip casting the query on nested arrays (gh-7098)' , function ( ) {
2540
+ const nestedSchema = new Schema ( {
2541
+ xyz : [ [ Number ] ]
2542
+ } ) ;
2543
+ const schema = new Schema ( {
2544
+ xyz : [ [ { type : Number } ] ] ,
2545
+ nested : nestedSchema
2546
+ } ) ;
2547
+
2548
+ const Model = db . model ( 'gh-7098' , schema ) ;
2549
+
2550
+ const test = new Model ( {
2551
+ xyz : [
2552
+ [ 0 , 1 ] ,
2553
+ [ 2 , 3 ] ,
2554
+ [ 4 , 5 ]
2555
+ ] ,
2556
+ nested : {
2557
+ xyz : [
2558
+ [ 0 , 1 ] ,
2559
+ [ 2 , 3 ] ,
2560
+ [ 4 , 5 ]
2561
+ ] ,
2562
+ }
2563
+ } ) ;
2564
+
2565
+ const cond = { _id : test . _id } ;
2566
+ const update = { $set : { 'xyz.1.0' : '200' , 'nested.xyz.1.0' : '200' } } ;
2567
+ const opts = { new : true } ;
2568
+
2569
+ return co ( function * ( ) {
2570
+ let inserted = yield test . save ( ) ;
2571
+ inserted = inserted . toObject ( ) ;
2572
+ assert . deepStrictEqual ( inserted . xyz , [ [ 0 , 1 ] , [ 2 , 3 ] , [ 4 , 5 ] ] ) ;
2573
+ assert . deepStrictEqual ( inserted . nested . xyz , [ [ 0 , 1 ] , [ 2 , 3 ] , [ 4 , 5 ] ] ) ;
2574
+ let updated = yield Model . findOneAndUpdate ( cond , update , opts ) ;
2575
+ updated = updated . toObject ( ) ;
2576
+ assert . deepStrictEqual ( updated . xyz , [ [ 0 , 1 ] , [ 200 , 3 ] , [ 4 , 5 ] ] ) ;
2577
+ assert . deepStrictEqual ( updated . nested . xyz , [ [ 0 , 1 ] , [ 200 , 3 ] , [ 4 , 5 ] ] ) ;
2578
+ } ) ;
2579
+ } ) ;
2580
+
2539
2581
it ( 'defaults with overwrite and no update validators (gh-5384)' , function ( done ) {
2540
2582
const testSchema = new mongoose . Schema ( {
2541
2583
name : String ,
0 commit comments