Exclude nested field from encryption Mongoose encryption

邮差的信 提交于 2021-02-11 13:49:01

问题


So i am using an npm package called mongoose-encryption all is great except one important thing. I have an array called reports and it has alot of objects in it. Each object has one unique field called report_id the thing is i need to perform a delete operation based on that ID but if i encrypt it mongoose apparently cant find it. For that i excluded some fields like the docs said but i cant apparently exclude a nested field i tried this:

usersSchema.plugin(encrypt,{secret:sigKey,excludeFromEncryption: ['username','reports.report_id']});

So the username is excluded from encryption but not the reports.report_id any ideas?


回答1:


The [document](https://www.npmjs.com/package/mongoose-encryption] says:

To encrypt, the relevant fields are removed from the document, converted to JSON, enciphered in Buffer format with the IV and plugin version prepended, and inserted into the _ct field of the document. Mongoose converts the _ct field to Binary when sending to mongo.

If the reports field is encrypted by mongoose-encryption, it will not be present at all in the document stored in MongoDB.

If you need the value of the reports.report_id field to be accessible in a query while encrypting the reports field, you'll need to copy them out to an array that is not being encrypted.



来源:https://stackoverflow.com/questions/61717801/exclude-nested-field-from-encryption-mongoose-encryption

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!