Skip to content

Commit

Permalink
types(schema): add missing search index types
Browse files Browse the repository at this point in the history
Support for MongoDB Atlas search indexes was added in [#14251](#14251)
but the types for `Schema.searchIndex` and the `autoSearchIndex` option
were missed.

Add these types so that the typescript definitions match the
capabilities of the JavaScript version of `mongoose`.
  • Loading branch information
noseworthy committed Mar 20, 2024
1 parent e3f3205 commit df9db3c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions types/index.d.ts
Expand Up @@ -274,6 +274,13 @@ declare module 'mongoose' {
/** Defines an index (most likely compound) for this schema. */
index(fields: IndexDefinition, options?: IndexOptions): this;

/**
* Define a search index for this schema.
*
* @remarks Search indexes are only supported when used against a 7.0+ Mongo Atlas cluster.
*/
searchIndex(description: mongodb.SearchIndexDescription): Promise<string>;

/**
* Returns a list of indexes that this schema declares, via `schema.index()`
* or by `index: true` in a path's options.
Expand Down
5 changes: 5 additions & 0 deletions types/schemaoptions.d.ts
Expand Up @@ -24,6 +24,11 @@ declare module 'mongoose' {
* automatic index builds, you can set autoIndex to false.
*/
autoIndex?: boolean;
/**
* Similar to autoIndex, except for automatically creates any Atlas search indexes defined in your
* schema. Unlike autoIndex, this option defaults to false.
*/
autoSearchIndex?: boolean;
/**
* If set to `true`, Mongoose will call Model.createCollection() to create the underlying collection
* in MongoDB if autoCreate is set to true. Calling createCollection() sets the collection's default
Expand Down

0 comments on commit df9db3c

Please sign in to comment.