Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileSchema.methods.write() generates a new ObjectId even when provided with one #79

Open
ncroese opened this issue Mar 7, 2022 · 0 comments

Comments

@ncroese
Copy link

ncroese commented Mar 7, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant