From f021c58233470ec0ccdbc8027e3806276f93c8be Mon Sep 17 00:00:00 2001 From: Valeri Karpov <val@karpov.io> Date: Tue, 2 Feb 2021 10:30:18 -0500 Subject: [PATCH 1/2] fix(operations): avoid hardcoding `checkKeys` for insert operations --- src/operations/insert.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/operations/insert.ts b/src/operations/insert.ts index 43418ab4341..f3a159f30cd 100644 --- a/src/operations/insert.ts +++ b/src/operations/insert.ts @@ -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 }; this.ns = ns; this.documents = documents; } From 986854e19522cc08ce06535e354ccf8dd6143cc6 Mon Sep 17 00:00:00 2001 From: Neal Beeken <neal.beeken@mongodb.com> Date: Tue, 2 Feb 2021 17:25:13 -0500 Subject: [PATCH 2/2] fix: Ensure checkKeys is defaulted to true --- src/operations/insert.ts | 2 +- test/functional/collection.test.js | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/operations/insert.ts b/src/operations/insert.ts index f3a159f30cd..17a9ee1b5b9 100644 --- a/src/operations/insert.ts +++ b/src/operations/insert.ts @@ -18,7 +18,7 @@ export class InsertOperation extends CommandOperation<Document> { constructor(ns: MongoDBNamespace, documents: Document[], options: BulkWriteOptions) { super(undefined, options); - this.options = { ...options }; + this.options = { ...options, checkKeys: options.checkKeys ?? true }; this.ns = ns; this.documents = documents; } diff --git a/test/functional/collection.test.js b/test/functional/collection.test.js index 3f2fc4548ed..42b96b575b7 100644 --- a/test/functional/collection.test.js +++ b/test/functional/collection.test.js @@ -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');