Tuesday 25 August 2020

What are these hidden mongoose properties in a document??

Hello all!I have a mongoose document retrieved from the database with the following type for example:interface Car { numberOfDoors: number; }If I do a console.log of the Car object retrieved from the database. I get numberOfDoors, _id and __v fields. Perfect until here. However, if I do the following:const aDifferentCar = { ...carFromDB, newProperty: blabla } Then if I console log aDifferentCar I get a bunch of mongoose properties, like $__, isNew, _doc, etc.Why this is not happening in the original console log? Also, what can I use to create another object based on other's properties but without using ...?I know calling lean() in the mongoose find would solve the issue. But I would like to avoid that as I will be using some virtual functions, etc. I have read in the documentations those will not be present with lean.Thank you in advance.

Submitted August 26, 2020 at 06:38AM by dejavits

No comments:

Post a Comment