diff --git a/src/db.ts b/src/db.ts index 35179e7369..38e006a9d5 100644 --- a/src/db.ts +++ b/src/db.ts @@ -798,7 +798,6 @@ const collectionKeys = [ * @param {object} [options.pkFactory] A primary key factory object for generation of custom _id keys. * @param {(ReadPreference|string)} [options.readPreference] The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST). * @param {boolean} [options.serializeFunctions=false] Serialize functions on any object. - * @param {boolean} [options.strict=false] Returns an error if the collection does not exist * @param {boolean} [options.capped=false] Create a capped collection. * @param {boolean} [options.autoIndexId=true] DEPRECATED: Create an index on the _id field of the document, True by default on MongoDB 2.6 - 3.0 * @param {number} [options.size] The size of the capped collection in bytes. diff --git a/src/operations/create_collection.ts b/src/operations/create_collection.ts index 03352de2dc..e36162d926 100644 --- a/src/operations/create_collection.ts +++ b/src/operations/create_collection.ts @@ -1,9 +1,6 @@ import CommandOperation = require('./command'); -import { ReadPreference } from '../read_preference'; import { Aspect, defineAspects } from './operation'; -import { applyWriteConcern } from '../utils'; import { loadCollection } from '../dynamic_loaders'; -import { MongoError } from '../error'; const ILLEGAL_COMMAND_FIELDS = new Set([ 'w', @@ -11,7 +8,6 @@ const ILLEGAL_COMMAND_FIELDS = new Set([ 'j', 'fsync', 'autoIndexId', - 'strict', 'serializeFunctions', 'pkFactory', 'raw', @@ -37,9 +33,6 @@ class CreateCollectionOperation extends CommandOperation { const options = this.options; const Collection = loadCollection(); - let listCollectionOptions = Object.assign({ nameOnly: true, strict: false }, options); - listCollectionOptions = applyWriteConcern(listCollectionOptions, { db }, listCollectionOptions); - function done(err: any) { if (err) { return callback(err); @@ -66,27 +59,6 @@ class CreateCollectionOperation extends CommandOperation { } } - const strictMode = listCollectionOptions.strict; - if (strictMode) { - db.listCollections({ name }, listCollectionOptions) - .setReadPreference(ReadPreference.PRIMARY) - .toArray((err?: any, collections?: any) => { - if (err) { - return callback(err); - } - - if (collections.length > 0) { - return callback( - new MongoError(`Collection ${name} already exists. Currently in strict mode.`) - ); - } - - super.executeCommand(server, cmd, done); - }); - - return; - } - // otherwise just execute the command super.executeCommand(server, cmd, done); } diff --git a/test/functional/collection.test.js b/test/functional/collection.test.js index 3f7f2bbfd6..0030fe5660 100644 --- a/test/functional/collection.test.js +++ b/test/functional/collection.test.js @@ -181,23 +181,6 @@ describe('Collection', function () { }); }); - it('should perform strict create collection', function (done) { - db.createCollection('test_strict_create_collection', (err, collection) => { - expect(err).to.not.exist; - expect(collection.collectionName).to.equal('test_strict_create_collection'); - - // Creating an existing collection should fail - db.createCollection('test_strict_create_collection', { strict: true }, err => { - expect(err).to.be.an.instanceof(Error); - expect(err.message).to.equal( - 'Collection test_strict_create_collection already exists. Currently in strict mode.' - ); - - done(); - }); - }); - }); - it('should fail to insert due to illegal keys', function (done) { db.createCollection('test_invalid_key_names', (err, collection) => { // Legal inserts @@ -480,21 +463,6 @@ describe('Collection', function () { }); }); - it('should fail due to existing collection', function (done) { - db.createCollection('shouldFailDueToExistingCollection', { strict: true }, (err, coll) => { - expect(err).to.not.exist; - expect(coll).to.exist; - - db.createCollection('shouldFailDueToExistingCollection', { strict: true }, err => { - expect(err).to.exist; - expect(err.message).to.equal( - 'Collection shouldFailDueToExistingCollection already exists. Currently in strict mode.' - ); - done(); - }); - }); - }); - const listCollectionsTests = [ { title: 'should filter correctly during list', diff --git a/test/unit/db_list_collections.test.js b/test/unit/db_list_collections.test.js index 087d511a99..87d0d596ea 100644 --- a/test/unit/db_list_collections.test.js +++ b/test/unit/db_list_collections.test.js @@ -41,11 +41,6 @@ describe('db.listCollections', function () { command: db => db.listCollections({}, { nameOnly: true }).toArray(() => {}), listCollectionsValue: true }, - { - description: 'should send nameOnly: true for db.createCollection', - command: db => db.createCollection('foo', { strict: true }, () => {}), - listCollectionsValue: true - }, { description: 'should send nameOnly: true for db.collections', command: db => db.collections(() => {}),