Closed jssuttles closed 8 years ago
Either that or just append the _id, like you do for save().
If you need an _id for an Embedded Document, then you don't need a Embedded Document. Just extends a regular Document from which you could use findOneAndUpdate.
Now, the problem as I see here, it's findOneAndUpdate in a id-less Embedded Document. Those functions may confuse you, and I think should be removed. :)
I think I might have misunderstood findOneAndUpdate. The value needs to be a normal object. It can't be a Document or contain EmbeddedDocuments. Is that right?
Alright. I figured it out. It does work. Just don't include an EmbeddedDocument in the value.
I just ran into a problem in which I was trying to findOneAndUpdate (with upsert: true) a new Document with an Embedded Document. The problem is that NeDB's deepcopy function doesn't save the Embedded Document's _schema correctly. Since the types in _schema are functions (i.e. String is a function), these get returned as undefined, which in Base Documents _fromData function it tries to check the documentClass of the undefined type. Possibly the _fromData function needs to know which _schema are available and rebuild it on the fly.