Skip to content

Commit ee8ca1a

Browse files
author
Thomas Reggi
authored
feat: adds "hidden" option when creating indexes
NODE-2591
1 parent e2f021d commit ee8ca1a

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/operations/indexes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const VALID_INDEX_OPTIONS = new Set([
1818
'name',
1919
'partialFilterExpression',
2020
'sparse',
21+
'hidden',
2122
'expireAfterSeconds',
2223
'storageEngine',
2324
'collation',

test/functional/index.test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,4 +1289,31 @@ describe('Indexes', function () {
12891289
)
12901290
);
12911291
});
1292+
1293+
it('should create index hidden', {
1294+
metadata: { requires: { mongodb: '>=4.4', topology: 'single' } },
1295+
test: function (done) {
1296+
const configuration = this.configuration;
1297+
const client = configuration.newClient(configuration.writeConcernMax(), { poolSize: 1 });
1298+
client.connect(function (err, client) {
1299+
expect(err).to.not.exist;
1300+
const db = client.db(configuration.db);
1301+
db.createCollection('hidden_index_collection', (err, collection) => {
1302+
expect(err).to.not.exist;
1303+
collection.createIndex('a', { hidden: true }, (err, index) => {
1304+
expect(err).to.not.exist;
1305+
expect(index).to.equal('a_1');
1306+
collection.listIndexes().toArray((err, indexes) => {
1307+
expect(err).to.not.exist;
1308+
expect(indexes).to.deep.equal([
1309+
{ v: 2, key: { _id: 1 }, name: '_id_' },
1310+
{ v: 2, key: { a: 1 }, name: 'a_1', hidden: true }
1311+
]);
1312+
client.close(done);
1313+
});
1314+
});
1315+
});
1316+
});
1317+
}
1318+
});
12921319
});

0 commit comments

Comments
 (0)