These are chat archives for Automattic/mongoose

19th
Feb 2019
hillct
@hillct
Feb 19 02:52
Good efening all. I need to clone a subdocument from a retrieved mongoose document object, but need to be sure that changes made to my cloned object do not make it back to the original. I found this very old discussion of this issue http://www.connecto.io/blog/deep-copyingcloning-of-mongoose-object/ but I wonder, Is there a newer best practice to handle this type of cloning?
hillct
@hillct
Feb 19 03:29
in this use case, I’ll need to be able to make chanhes to the original, other changes to the clone, then save the original document, having it save only the changes I made to the original and NOT the clone
hillct
@hillct
Feb 19 03:54
I see that document.toObject() might be a suitable solution, but behavior related to subdocuments seems inconsistant with documentation as described here https://alexanderzeitler.com/articles/mongoose-tojson-toobject-transform-with-subdocuments/ any guidance?
David Ferguson
@jdfwarrior
Feb 19 17:14
After doing some more digging, it appears that utils.getFunctionName is giving an incorrect value but I'm still attempting to track down why. obj.constructor shows as f Object() { [native code] } which looks correct but passing it into utils.getFunctionName returns "Cartographic" so, within interpretAsType it ends up trying to identify what the property is instead of the nested values. For instance, if name was the top property with nested properties inside of first and last, its supposed to adjust the path to name.first and in this instance, it doesn't