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

documents with select false field which is an object(not mixed type) doesn't update without markModified, even though fields were explicitly selected when querying for document #8404

Closed
r3wt opened this issue Dec 6, 2019 · 2 comments

Comments

@r3wt
Copy link

r3wt commented Dec 6, 2019

It happens on multiple models for us, so i felt like maybe i should report it. I apologize if its a known issue, but my time is scant, far too scant at this particular moment to search through issues to see if its a duplicate.

const fooSchema =  new Schema({
	foo: { type: String },
	sensitive_field:{
		select: false,
		type:{
			field1: { type: String, default: null },
			field2: { type: String, default: null },
			field3: { type: String, enum:['inactive','active','cancelled','grace','suspended'], default:'inactive' },
			field4: { type: String, enum:[ 'active','none','expired','expires_soon' ], default:'none' },
			field5: { type: Boolean, default: false }
		}
	},
});

This is roughly what one such field looks like, as shown here sensitive_field. without calling doc.markModified('sensitive_field'); document is not updated with changes to this field.

@vkarpov15
Copy link
Collaborator

That's because your schema as written defines sensitive_field as a Mixed type. We unfortunately don't support defining type as a POJO. You would need to do this:

const fooSchema =  new Schema({
	foo: { type: String },
	sensitive_field:{
		select: false,
		type: new Schema({
			field1: { type: String, default: null },
			field2: { type: String, default: null },
			field3: { type: String, enum:['inactive','active','cancelled','grace','suspended'], default:'inactive' },
			field4: { type: String, enum:[ 'active','none','expired','expires_soon' ], default:'none' },
			field5: { type: Boolean, default: false }
		}
	},
});

Re: #7181, this behavior is risky and counter intuitive, and we'll change it going forward.

@r3wt
Copy link
Author

r3wt commented Dec 9, 2019

@vkarpov15 thanks for the info, the workaround you provided is sufficient. I appreciate you helping me

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

2 participants