diff --git a/src/operations/indexes.ts b/src/operations/indexes.ts index 661fcf6e22..2949ca25fa 100644 --- a/src/operations/indexes.ts +++ b/src/operations/indexes.ts @@ -71,7 +71,29 @@ export type IndexSpecification = OneOrMore< >; /** @public */ -export interface IndexDescription extends CreateIndexesOptions { +export interface IndexDescription + extends Pick< + CreateIndexesOptions, + | 'background' + | 'unique' + | 'partialFilterExpression' + | 'sparse' + | 'hidden' + | 'expireAfterSeconds' + | 'storageEngine' + | 'collation' + | 'version' + | 'weights' + | 'default_language' + | 'language_override' + | 'textIndexVersion' + | '2dsphereIndexVersion' + | 'bits' + | 'min' + | 'max' + | 'bucketSize' + | 'wildcardProjection' + > { collation?: CollationOptions; name?: string; key: Document; @@ -96,7 +118,7 @@ export interface CreateIndexesOptions extends CommandOperationOptions { /** (MongoDB 4.4. or higher) Specifies how many data-bearing members of a replica set, including the primary, must complete the index builds successfully before the primary marks the indexes as ready. This option accepts the same values for the "w" field in a write concern plus "votingMembers", which indicates all voting data-bearing nodes. */ commitQuorum?: number | string; /** Specifies the index version number, either 0 or 1. */ - version: number; + version?: number; // text indexes weights?: Document; default_language?: string; @@ -115,7 +137,7 @@ export interface CreateIndexesOptions extends CommandOperationOptions { // wildcard indexes wildcardProjection?: Document; /** Specifies that the index should exist on the target collection but should not be used by the query planner when executing operations. (MongoDB 4.4 or higher) */ - hidden: boolean; + hidden?: boolean; } function makeIndexSpec(indexSpec: IndexSpecification, options: any): IndexDescription { diff --git a/test/types/index_options.test-d.ts b/test/types/index_options.test-d.ts index 8beb0b4d00..65e14f7a70 100644 --- a/test/types/index_options.test-d.ts +++ b/test/types/index_options.test-d.ts @@ -1,28 +1,25 @@ import { expectType, expectNotType } from 'tsd'; -import { IndexDescription } from '../../src'; +import type { IndexDescription } from '../../src'; // test that all valid index options are allowed in IndexDefinitions -expectType({ - key: {}, - background: true, - expireAfterSeconds: 2400, - name: 'index_1', - sparse: true, - storageEngine: {}, - unique: true, - version: 1, - default_language: 'english', - language_override: 'english', - textIndexVersion: 2, - weights: {}, - '2dsphereIndexVersion': 2, - bits: 1, - max: 1.1, - min: 9.9, - bucketSize: 100, - partialFilterExpression: {}, - collation: { locale: 'en' }, - wildcardProjection: {}, - hidden: true -}); +expectType({ key: {}, background: true }); +expectType({ key: {}, expireAfterSeconds: 2400 }); +expectType({ key: {}, name: 'index_1' }); +expectType({ key: {}, sparse: true }); +expectType({ key: {}, storageEngine: {} }); +expectType({ key: {}, unique: true }); +expectType({ key: {}, version: 1 }); +expectType({ key: {}, default_language: 'english' }); +expectType({ key: {}, language_override: 'english' }); +expectType({ key: {}, textIndexVersion: 2 }); +expectType({ key: {}, weights: {} }); +expectType({ key: {}, '2dsphereIndexVersion': 2 }); +expectType({ key: {}, bits: 1 }); +expectType({ key: {}, max: 1.1 }); +expectType({ key: {}, min: 9.9 }); +expectType({ key: {}, bucketSize: 100 }); +expectType({ key: {}, partialFilterExpression: {} }); +expectType({ key: {}, collation: { locale: 'en' } }); +expectType({ key: {}, wildcardProjection: {} }); +expectType({ key: {}, hidden: true }); expectNotType({ key: {}, invalidOption: 2400 });