File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -4383,4 +4383,33 @@ describe('Query', function() {
4383
4383
await Error . find ( ) . sort ( '-' ) ;
4384
4384
} , { message : 'Invalid field "" passed to sort()' } ) ;
4385
4385
} ) ;
4386
+
4387
+ it ( 'does not apply sibling path defaults if using nested projection (gh-14115)' , async function ( ) {
4388
+ const userSchema = new mongoose . Schema ( {
4389
+ name : String ,
4390
+ account : {
4391
+ amount : Number ,
4392
+ owner : { type : String , default : ( ) => 'OWNER' } ,
4393
+ taxIds : [ Number ]
4394
+ }
4395
+ } ) ;
4396
+ const User = db . model ( 'User' , userSchema ) ;
4397
+
4398
+ const { _id } = await User . create ( {
4399
+ name : 'test' ,
4400
+ account : {
4401
+ amount : 25 ,
4402
+ owner : 'test' ,
4403
+ taxIds : [ 42 ]
4404
+ }
4405
+ } ) ;
4406
+
4407
+ const doc = await User
4408
+ . findOne ( { _id } , { name : 1 , account : { amount : 1 } } )
4409
+ . orFail ( ) ;
4410
+ assert . strictEqual ( doc . name , 'test' ) ;
4411
+ assert . strictEqual ( doc . account . amount , 25 ) ;
4412
+ assert . strictEqual ( doc . account . owner , undefined ) ;
4413
+ assert . strictEqual ( doc . account . taxIds , undefined ) ;
4414
+ } ) ;
4386
4415
} ) ;
You can’t perform that action at this time.
0 commit comments