You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When FileSchema.methods.write() is called it makes a copy of the model instance to use certain properties from, including _id. However, the method to copy the model, copyInstance() from mongoose-common, will remove the _id property from the copy, causing in a new ObjectId to be generated for the file. This results in a mismatch between the model ObjectId and the ObjectId of the file in the database.
The reason for this is that in copyInstance() a method named mergeObjects() from the common library is used, which in turn uses the compact() method. This method uses isNotValue(), which returns true for mongodb.ObjectId objects, resulting in these type of objects from being filtered from the copied instance.
I think it would be best to fix this in the isNotValue() method of the common library, making sure it returns false for mongodb.ObjectId objects.
A workaround might be to make sure to send the ObjectId to the copyInstance() method as a String type instead, or add the ObjectId to the file instance later.
The text was updated successfully, but these errors were encountered:
When
FileSchema.methods.write()
is called it makes a copy of the model instance to use certain properties from, including_id
. However, the method to copy the model,copyInstance()
frommongoose-common
, will remove the_id
property from the copy, causing in a new ObjectId to be generated for the file. This results in a mismatch between the model ObjectId and the ObjectId of the file in the database.The reason for this is that in
copyInstance()
a method namedmergeObjects()
from thecommon
library is used, which in turn uses thecompact()
method. This method usesisNotValue()
, which returnstrue
formongodb.ObjectId
objects, resulting in these type of objects from being filtered from the copied instance.I think it would be best to fix this in the
isNotValue()
method of thecommon
library, making sure it returnsfalse
formongodb.ObjectId
objects.A workaround might be to make sure to send the ObjectId to the
copyInstance()
method as a String type instead, or add the ObjectId to the file instance later.The text was updated successfully, but these errors were encountered: