@@ -22,7 +22,6 @@ const clone = require('./helpers/clone');
22
22
const compile = require ( './helpers/document/compile' ) . compile ;
23
23
const defineKey = require ( './helpers/document/compile' ) . defineKey ;
24
24
const flatten = require ( './helpers/common' ) . flatten ;
25
- const get = require ( './helpers/get' ) ;
26
25
const getEmbeddedDiscriminatorPath = require ( './helpers/document/getEmbeddedDiscriminatorPath' ) ;
27
26
const getKeysInSchemaOrder = require ( './helpers/schema/getKeysInSchemaOrder' ) ;
28
27
const getSubdocumentStrictValue = require ( './helpers/schema/getSubdocumentStrictValue' ) ;
@@ -3798,15 +3797,7 @@ Document.prototype.$__handleReject = function handleReject(err) {
3798
3797
*/
3799
3798
3800
3799
Document . prototype . $toObject = function ( options , json ) {
3801
- const path = json ? 'toJSON' : 'toObject' ;
3802
- const baseOptions = this . constructor &&
3803
- this . constructor . base &&
3804
- this . constructor . base . options &&
3805
- get ( this . constructor . base . options , path ) || { } ;
3806
- const schemaOptions = this . $__schema && this . $__schema . options || { } ;
3807
- // merge base default options with Schema's set default options if available.
3808
- // `clone` is necessary here because `utils.options` directly modifies the second input.
3809
- const defaultOptions = Object . assign ( { } , baseOptions , schemaOptions [ path ] ) ;
3800
+ const defaultOptions = this . $__schema . _getDefaultToObjectOptions ( ) ;
3810
3801
3811
3802
// If options do not exist or is not an object, set it to empty object
3812
3803
options = utils . isPOJO ( options ) ? { ...options } : { } ;
@@ -3815,10 +3806,8 @@ Document.prototype.$toObject = function(options, json) {
3815
3806
let _minimize ;
3816
3807
if ( options . _calledWithOptions . minimize != null ) {
3817
3808
_minimize = options . minimize ;
3818
- } else if ( defaultOptions . minimize != null ) {
3819
- _minimize = defaultOptions . minimize ;
3820
3809
} else {
3821
- _minimize = schemaOptions . minimize ;
3810
+ _minimize = defaultOptions . minimize ;
3822
3811
}
3823
3812
3824
3813
options . minimize = _minimize ;
@@ -3842,14 +3831,8 @@ Document.prototype.$toObject = function(options, json) {
3842
3831
}
3843
3832
options . _isNested = true ;
3844
3833
options . json = json ;
3845
- options . minimize = _minimize ;
3846
-
3847
3834
options . _parentOptions = options ;
3848
-
3849
3835
options . _skipSingleNestedGetters = false ;
3850
- // remember the root transform function
3851
- // to save it from being overwritten by sub-transform functions
3852
- // const originalTransform = options.transform;
3853
3836
3854
3837
let ret = clone ( this . _doc , options ) || { } ;
3855
3838
0 commit comments