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

Nested Fields create an empty object if the parent field doesn't exist #66

Open
grrseguin opened this issue Nov 1, 2017 · 4 comments
Open

Comments

@grrseguin
Copy link

grrseguin commented Nov 1, 2017

Hello,

With the config above a new document will always have field1: {} if field1 is not provided.

const subUserSchema = new Schema({
  field2: {
    type: String,
  },
});

const userSchema = new Schema({
  field1: {
    type: subUserSchema,
  },
});

userSchema.plugin(encrypt, { encryptionKey: encKey, signingKey: sigKey, encryptedFields: ["field1.field2"], });

IMHO, field1 should not be created, WDYT?

Version "mongoose-encryption": "1.5.0",

@joegoldbeck
Copy link
Owner

I definitely agree. I wonder if this relates to #65

I don't have time to dig into this in the near-term, but would be happy to review any PRs accompanied with tests!

@grrseguin
Copy link
Author

grrseguin commented Nov 3, 2017

Why not for the PR.

But before, by reading the Encrypt Specific Fields of Sub Docs section in the README.md file, i resolved the problem.

const subUserSchema = new Schema({
  field2: {
    type: String,
  },
});

subUserSchema.plugin(encrypt, { encryptionKey: encKey, signingKey: sigKey, encryptedFields: ["field2"], });

const userSchema = new Schema({
  field1: {
    type: subUserSchema,
  },
});

@grrseguin
Copy link
Author

grrseguin commented Nov 3, 2017

Maybe Nested Fields section should be replaced by Encrypt Specific Fields of Sub Docs section in the README file.

I don't see any differences between nested fields & sub docs, WDYT ?

@joegoldbeck
Copy link
Owner

Ah that makes sense. Apparently there is a difference at the Mongoose level (though Mongo itself of course doesn't really care), hence the support for both.

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

No branches or pull requests

2 participants