Skip to content

Commit 46a959b

Browse files
vkarpov15ljhaywar
authored andcommitted
fix(operations): avoid hardcoding checkKeys for insert operations (#2726)
1 parent 6187a5b commit 46a959b

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/operations/insert.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class InsertOperation extends CommandOperation<Document> {
1818

1919
constructor(ns: MongoDBNamespace, documents: Document[], options: BulkWriteOptions) {
2020
super(undefined, options);
21-
this.options = { ...options, checkKeys: true };
21+
this.options = { ...options, checkKeys: options.checkKeys ?? true };
2222
this.ns = ns;
2323
this.documents = documents;
2424
}

test/functional/collection.test.js

+10
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,16 @@ describe('Collection', function () {
269269
});
270270
});
271271

272+
it('should permit insert of dot and dollar keys if requested', function () {
273+
const collection = db.collection('test_invalid_key_names');
274+
return Promise.all([
275+
collection.insertOne({ hel$lo: 0 }, { checkKeys: false }),
276+
collection.insertOne({ hello: { $hello: 0 } }, { checkKeys: false }), // embedded document can have a leading dollar
277+
collection.insertOne({ 'hel.lo': 0 }, { checkKeys: false }),
278+
collection.drop()
279+
]);
280+
});
281+
272282
it('should fail due to illegal listCollections', function (done) {
273283
db.collection(5, err => {
274284
expect(err.message).to.equal('collection name must be a String');

0 commit comments

Comments
 (0)