问题
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