From ee8ca1aaddd1da33689a49c99dcc1c6f42b6f9dd Mon Sep 17 00:00:00 2001 From: Thomas Reggi Date: Fri, 25 Sep 2020 11:42:56 -0400 Subject: [PATCH] feat: adds "hidden" option when creating indexes NODE-2591 --- src/operations/indexes.ts | 1 + test/functional/index.test.js | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/operations/indexes.ts b/src/operations/indexes.ts index a5d171d414..ce10bea78d 100644 --- a/src/operations/indexes.ts +++ b/src/operations/indexes.ts @@ -18,6 +18,7 @@ const VALID_INDEX_OPTIONS = new Set([ 'name', 'partialFilterExpression', 'sparse', + 'hidden', 'expireAfterSeconds', 'storageEngine', 'collation', diff --git a/test/functional/index.test.js b/test/functional/index.test.js index 87aff07137..31ba5d3cea 100644 --- a/test/functional/index.test.js +++ b/test/functional/index.test.js @@ -1289,4 +1289,31 @@ describe('Indexes', function () { ) ); }); + + it('should create index hidden', { + metadata: { requires: { mongodb: '>=4.4', topology: 'single' } }, + test: function (done) { + const configuration = this.configuration; + const client = configuration.newClient(configuration.writeConcernMax(), { poolSize: 1 }); + client.connect(function (err, client) { + expect(err).to.not.exist; + const db = client.db(configuration.db); + db.createCollection('hidden_index_collection', (err, collection) => { + expect(err).to.not.exist; + collection.createIndex('a', { hidden: true }, (err, index) => { + expect(err).to.not.exist; + expect(index).to.equal('a_1'); + collection.listIndexes().toArray((err, indexes) => { + expect(err).to.not.exist; + expect(indexes).to.deep.equal([ + { v: 2, key: { _id: 1 }, name: '_id_' }, + { v: 2, key: { a: 1 }, name: 'a_1', hidden: true } + ]); + client.close(done); + }); + }); + }); + }); + } + }); });