Open hasezoey opened 2 years ago
Is there any fix for this?
this project has not been updated since the creation of this issue, so there is no "official" fix, typegoose uses a workaround for _id
, which would need to be repeated for all ObjectId
s and likely does not apply to all use-cases (or maybe there is some kind of global transform, i dont know)
Description
when using
Transform
with mongoose 6.0 (6.0.0-rc1
) and / or mongodb4.x.x
, thevalue
andobj.key
are different values(Note: in this case
key
is for_id
which ismongoose.Types.ObjectId
instance)Minimal code-snippet showcasing the problem
Output
Note: some comments added, starting with `# ` ``` yarn run v1.22.10 $ ts-node ./src/test.ts saved 6116693687f80aa238917279 pojo { _id: new ObjectId("6116693687f80aa238917279"), email: 'somebody@gmail.com', password: 'secret', __v: 0 } true value { value: new ObjectId("6116693687f80aa23891727c"), # this is different key: '_id', obj: { _id: new ObjectId("6116693687f80aa238917279"), # with this email: 'somebody@gmail.com', password: 'secret', __v: 0 }, type: 0, options: { enableCircularCheck: false, enableImplicitConversion: false, excludeExtraneousValues: false, excludePrefixes: undefined, exposeDefaultValues: false, exposeUnsetFields: true, groups: undefined, ignoreDecorators: false, strategy: undefined, targetMaps: undefined, version: undefined } } value and obj.key are different! ctp { _id: '6116693687f80aa23891727c', __v: 0, email: 'somebody@gmail.com' } false false Done in 2.94s. ```Reproduction Repository & Branch: https://github.com/typegoose/typegoose-testing/tree/verifyCTandM6Issue
Note: the example is taken from typegoose's tests and minified for reproduction (the linked branch is where typegoose is using mongoose 6.0)
Steps:
yarn install
yarn run run:directly
(to ignore typescript errors) [yes, its run withts-node
, but same behavior when usingtsc
(also ignoring types errors]Expected behavior
Expected that
value
andobj.key
to be the same propertyActual behavior
value
andobj.key
are differentPS: this might also just be a
question
, i just dont know what pre-transformations are applied, i just noticed that the value are different