tblobaum/mongoose-troop

merge doesn't work on deep paths

Opened this issue · 1 comments

First, thanks for the really useful library.

The merge utility doesn't appear to work on deeply nested paths. For example, if I have a schema:

name:
    first: String
    last: String

then the first and last properties aren't merged into the parent object. It looks like this is because the value is retrieved on the source document by array getter (e.g. doc[name]), and when name is "name.first" the retrieval fails.

(I think this is relatively straightforward to fix, but I also believe you need to code for edge cases around circular references, which if is the case complicates things some. it's possible the code from node.extend could be leveraged?...)

I'll look into this. Merge has a few edge cases that will probably never work, like arrays and embedded docs. This can work though, it's going to be similar to a deep extend or clone