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

fix(operations): avoid hardcoding checkKeys for insert operations #2726

Merged
merged 2 commits into from
Feb 2, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/operations/insert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class InsertOperation extends CommandOperation<Document> {

constructor(ns: MongoDBNamespace, documents: Document[], options: BulkWriteOptions) {
super(undefined, options);
this.options = { ...options, checkKeys: true };
this.options = { ...options };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change removes the default to true behavior, I didn't dig further into 3.6 to see where we were doing the defaulting but for the sake of this version we can do it here in the constructor.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a note, for server version 3.6 the server started allowing "." and "$" in field names, so it seems making the default not validate them here makes sense going forward.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either way, we should make a note in the changelog if the checkKeys behavior changed. In node driver 3.6, you couldn't use dotted keys unless you explicitly set checkKeys: false

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to clarify: as it stands with the merged change, the behavior is the same as 3.6 (no dots/dollars allowed unless checkKeys: false).

I would say even though the server permits dots and dollars it seems fair to leave the ability to insert documents with such keys under a flag given the inability at this time to query documents with such keys. There is work planned to allow querying such documents here SERVER-30575. Maybe that's a time to reconsider gating this behavior with a flag.

However since this driver supports server versions back to 2.6 where these keys wouldn't be permitted I think its an acceptable footgun prevention measure we can hold on to.

this.ns = ns;
this.documents = documents;
}
Expand Down