These are chat archives for Automattic/mongoose

8th
Nov 2017
Fabian Kögel
@Faibk
Nov 08 2017 13:35
Hi, I have a model M and a discriminator D on it, adding an additional field F of type String. If I create an instance with M.create({__t:D, F:"1"}) it saves the discriminator type and field correctly. On updating the instance with M.findOneAndUpdate({_id:xx, __t:D, F:"2"}) the field F is not updated... does anybody have a clue why this happens?
Since I can create an instance of a discriminator via the base model, I suppose you can also use the update methods on the base model the same way (by just providing the __t discriminator type)?
Fabian Kögel
@Faibk
Nov 08 2017 14:54
Hm, I looked into the mongoose source code and it seems, that the discriminator is looked up for the create method on the base model but not for findOneAndUpdate. Seems like an inconsistency in the API, but I will just do the same lookup of the discriminator model myself and call findOneAndUpdate on it directly. :smile: