-
Notifications
You must be signed in to change notification settings - Fork 32
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
nested field encryption support #34
Comments
After having a look at the closed issues I realized there was a similar issue #1 (and merge request at the end) closed due to inactivity. It would be useful to add this feature. |
@caltuntas I'll have a look at this again. The merge request you reference actually incorrectly mentioned the issue in question. I cannot guarantee how fast I'll be able to develop this but let's say after the holidays would be a fair bet :) |
Fair enough :) If I can find some time before you I may add this and make a pull request. Thanks |
@caltuntas I had a look at this issue again and while implementing it would be possible, it would vastly complicate the code (and potentially break the current encrypted field naming convention). I personally think that if you require nested field encryption, you could consider having sub-documents and apply the plugin on them and let mongoose itself handle the magic. What do you think? |
@wheresvic's suggestion on using subdocuments works perfectly. For those of you looking for a simple code example, consider the following.
That's a stripped down version of what I'm using to store OAuth credentials for multiple service providers for multiple users on an open source project I'm currently working on. Hopefully this code helps someone. |
|
I did this |
I experienced some issue with a similar structure like "Account schema has an array of Credential Schema, in which a field is marked as encrypted". After I use
when I call It seems like only happens to Array type, and I found using `account.markModified('credentials') solves this problem. I'm not sure if this behaviour is mentioned anywhere but since it is kind of related to the implementation described in this issue, I though I'd just post it here. |
I tried following the suggestion proposed by @rickmacgillis but it's not working on my side. I have an UserSchema where I need to encrypt the "name" and "surname" fields. Then this schema contains a field "extra" which is based on another schema (as it is a nested object). Unfortunately, I'm having some issues with this scenario. Therefore, the fields specified in the UserSchema are successfully encrypted, while the ones in the UserExtraSchema are not. Below a snippet showing what I'm trying to do.
|
Added test: mongoose-field-encryption/test/test-db.js Line 212 in 036917d
|
I have the same issue |
@mexusbg there is a test that uses exactly this example and it is working fine: mongoose-field-encryption/test/test-db.js Line 212 in 036917d
the only difference I see from the example code is the way the The other point is that I do not see how you save and retrieve the document. Are you saving the main user document? |
@wheresvic |
I have the same problem with subschema encryption when I use findOneAndUpdate() on the parent record, but when I switched to save(), it works. |
I'm encountering the same issue on Update/UpdateOne. I see that it's all over our project. |
Hello,
Firstly I want to thank you for this nice library. At the moment, library supports only outer level field encryption like in the PostSchema example you added. It can only encrypt "references" field as whole. But when only one of the fields inside "references" should be encrypted, it doesn't work.
So It would be nice to support nested field encryption with "dot notation" used in mongoDB itself.
Query on Nested Field
For example , I should be able to define nested field as below
PostSchema.plugin(mongooseFieldEncyption, { fields: ["message", "references.author"], secret: "some secret key" });
and it should only encrypt "references.author" not whole "references" field
The text was updated successfully, but these errors were encountered: