mongoose: Deep cloning a mongoose model with arrays inside doesn't work after #6431
I’m using MongoDB 3.6.5 Community, NodeJS 9.11.1 and Mongoose 5.1.2, on Ubuntu 16.04.
Before the changes introduced in this commit to fix #6431, it was possible to do a
_.deepClone(mongooseModel)
where _ is lodash 4.11.1 and mongooseModel is a document that holds an array as one of its properties in the schema.
The error shown in the console looks like the following:
(node:58559) UnhandledPromiseRejectionWarning: TypeError: Class constructor CoreMongooseArray cannot be invoked without ‘new’
Would it be possible to change the way CoreMongooseArray has been implemented in order to make it easier to deep clone?
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 18 (2 by maintainers)
@valterkraemer I was able to reproduce with lodash 4.17.4 and confirm that 4.17.10 fixes it. Thanks for reporting this, I’m glad it’s sorted out.
Is there a unit test for this? I’m seeing the same issue now with
mongoose@6.1.4
andlodash@4.17.21
Using MongoDB
3.6.3
, Mongoose5.1.2
, Lodash4.17.4
I get the ErrorUnhandled rejection TypeError: Class constructor CoreMongooseArray cannot be invoked without 'new'
. But after updating Lodash to4.17.10
I don’t get the error anymore.Thank you all for your time. As @valterkraemer and @lineus reported, upgrading lodash to 4.17.10 fixed the problem.