File tree Expand file tree Collapse file tree 3 files changed +36
-9
lines changed Expand file tree Collapse file tree 3 files changed +36
-9
lines changed Original file line number Diff line number Diff line change @@ -11,12 +11,12 @@ jobs:
11
11
strategy :
12
12
fail-fast : false
13
13
matrix :
14
- node : [16, 18, 20]
15
- os : [ubuntu-20 .04]
14
+ node : [18, 20, 22 ]
15
+ os : [ubuntu-22 .04]
16
16
include :
17
- - os : ubuntu-20 .04
18
- mongo-os : ubuntu2004
19
- mongo : 5 .0.2
17
+ - os : ubuntu-22 .04
18
+ mongo-os : ubuntu2204
19
+ mongo : 7 .0.12
20
20
name : Node ${{ matrix.node }} MongoDB ${{ matrix.mongo }}
21
21
steps :
22
22
- uses : actions/checkout@a12a3943b4bdde767164f792f33f40b04645d846 # v3
36
36
printf "\n--timeout 8000" >> ./test/mocha.opts
37
37
./mongodb-linux-x86_64-${{ matrix.mongo-os }}-${{ matrix.mongo }}/bin/mongod --setParameter ttlMonitorSleepSecs=1 --fork --dbpath ./data/db/27017 --syslog --port 27017
38
38
sleep 2
39
- mongod --version
39
+ ./mongodb-linux-x86_64-${{ matrix.mongo-os }}-${{ matrix.mongo }}/bin/ mongod --version
40
40
echo `pwd`/mongodb-linux-x86_64-${{ matrix.mongo-os }}-${{ matrix.mongo }}/bin >> $GITHUB_PATH
41
41
- run : npm test
Original file line number Diff line number Diff line change @@ -117,11 +117,11 @@ function applyGettersToDoc(schema, doc) {
117
117
val [ i ] = schematype . caster . applyGetters ( val [ i ] , doc ) ;
118
118
}
119
119
}
120
- } if ( val && typeof val === 'object' && schematype . $isSingleNested ) {
120
+ } else if ( val && typeof val === 'object' && schematype . $isSingleNested ) {
121
121
applyGettersToDoc . call ( this , schematype . schema , val ) ;
122
- } else {
123
- mpath . set ( path , val , doc ) ;
124
122
}
123
+
124
+ mpath . set ( path , val , doc ) ;
125
125
} ) ;
126
126
}
127
127
Original file line number Diff line number Diff line change @@ -550,4 +550,31 @@ describe('mongoose-lean-getters', function() {
550
550
} ) ;
551
551
assert . strictEqual ( account . name , 'HamoBoker' ) ;
552
552
} ) ;
553
+
554
+ it ( 'applies single nested subdoc getters (gh-45)' , async function ( ) {
555
+ const priceSchema = new mongoose . Schema (
556
+ {
557
+ amount : mongoose . Schema . Types . Decimal128 ,
558
+ currency : String ,
559
+ } ,
560
+ { _id : false }
561
+ ) ;
562
+
563
+ const itemSchema = new mongoose . Schema ( {
564
+ name : String ,
565
+ price : {
566
+ type : priceSchema ,
567
+ get : v => ( { value : parseFloat ( v . amount . toString ( ) ) , unit : v . currency } )
568
+ } ,
569
+ } ) ;
570
+ itemSchema . plugin ( mongooseLeanGetters ) ;
571
+ const Item = mongoose . model ( 'gh-45-single-nested-getters' , itemSchema ) ;
572
+ await Item . create ( {
573
+ name : 'Test Product' ,
574
+ price : { amount : 123.45 , currency : 'USD' } ,
575
+ } ) ;
576
+
577
+ const lean = await Item . findOne ( ) . lean ( { getters : true } ) ;
578
+ assert . deepStrictEqual ( lean . price , { value : 123.45 , unit : 'USD' } ) ;
579
+ } ) ;
553
580
} ) ;
You can’t perform that action at this time.
0 commit comments