Skip to content

Commit

Permalink
fix(operations): avoid hardcoding checkKeys for insert operations (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Feb 2, 2021
1 parent 8a678e9 commit 5ce9b25
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
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, checkKeys: options.checkKeys ?? true };
this.ns = ns;
this.documents = documents;
}
Expand Down
10 changes: 10 additions & 0 deletions test/functional/collection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,16 @@ describe('Collection', function () {
});
});

it('should permit insert of dot and dollar keys if requested', function () {
const collection = db.collection('test_invalid_key_names');
return Promise.all([
collection.insertOne({ hel$lo: 0 }, { checkKeys: false }),
collection.insertOne({ hello: { $hello: 0 } }, { checkKeys: false }), // embedded document can have a leading dollar
collection.insertOne({ 'hel.lo': 0 }, { checkKeys: false }),
collection.drop()
]);
});

it('should fail due to illegal listCollections', function (done) {
db.collection(5, err => {
expect(err.message).to.equal('collection name must be a String');
Expand Down

0 comments on commit 5ce9b25

Please sign in to comment.