File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -12520,6 +12520,36 @@ describe('document', function() {
12520
12520
await doc . save ( ) ;
12521
12521
assert . strictEqual ( attachmentSchemaPreValidateCalls , 1 ) ;
12522
12522
} ) ;
12523
+
12524
+ it ( 'avoids creating separate subpaths entry for every element in array (gh-13874)' , async function ( ) {
12525
+ const tradeSchema = new mongoose . Schema ( { tradeId : Number , content : String } ) ;
12526
+
12527
+ const testSchema = new mongoose . Schema (
12528
+ {
12529
+ userId : Number ,
12530
+ tradeMap : {
12531
+ type : Map ,
12532
+ of : tradeSchema
12533
+ }
12534
+ }
12535
+ ) ;
12536
+
12537
+ const TestModel = db . model ( 'Test' , testSchema ) ;
12538
+
12539
+
12540
+ const userId = 100 ;
12541
+ const user = await TestModel . create ( { userId, tradeMap : new Map ( ) } ) ;
12542
+
12543
+ // add subDoc
12544
+ for ( let id = 1 ; id <= 10 ; id ++ ) {
12545
+ const trade = { tradeId : id , content : 'test' } ;
12546
+ user . tradeMap . set ( trade . tradeId . toString ( ) , trade ) ;
12547
+ }
12548
+ await user . save ( ) ;
12549
+ await TestModel . deleteOne ( { userId } ) ;
12550
+
12551
+ assert . equal ( Object . keys ( TestModel . schema . subpaths ) . length , 3 ) ;
12552
+ } ) ;
12523
12553
} ) ;
12524
12554
12525
12555
describe ( 'Check if instance function that is supplied in schema option is availabe' , function ( ) {
You can’t perform that action at this time.
0 commit comments