File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -1655,6 +1655,31 @@ Model.dropSearchIndex = async function dropSearchIndex(name) {
16551655 return await this . $__collection . dropSearchIndex ( name ) ;
16561656} ;
16571657
1658+ /**
1659+ * List all [Atlas search indexes](https://www.mongodb.com/docs/atlas/atlas-search/create-index/) on this model's collection.
1660+ * This function only works when connected to MongoDB Atlas.
1661+ *
1662+ * #### Example:
1663+ *
1664+ * const schema = new Schema({ name: { type: String, unique: true } });
1665+ * const Customer = mongoose.model('Customer', schema);
1666+ *
1667+ * await Customer.createSearchIndex({ name: 'test', definition: { mappings: { dynamic: true } } });
1668+ * const res = await Customer.listSearchIndexes(); // Includes `[{ name: 'test' }]`
1669+ *
1670+ * @param {Object } [options]
1671+ * @return {Promise<Array> }
1672+ * @api public
1673+ */
1674+
1675+ Model . listSearchIndexes = async function listSearchIndexes ( options ) {
1676+ _checkContext ( this , 'listSearchIndexes' ) ;
1677+
1678+ const cursor = await this . $__collection . listSearchIndexes ( options ) ;
1679+
1680+ return await cursor . toArray ( ) ;
1681+ } ;
1682+
16581683/**
16591684 * Does a dry-run of `Model.syncIndexes()`, returning the indexes that `syncIndexes()` would drop and create if you were to run `syncIndexes()`.
16601685 *
Original file line number Diff line number Diff line change @@ -544,6 +544,12 @@ declare module 'mongoose' {
544544 Array < MergeType < THydratedDocumentType , Omit < DocContents , '_id' > > >
545545 > ;
546546
547+ /**
548+ * List all [Atlas search indexes](https://www.mongodb.com/docs/atlas/atlas-search/create-index/) on this model's collection.
549+ * This function only works when connected to MongoDB Atlas.
550+ */
551+ listSearchIndexes ( options ?: mongodb . ListSearchIndexesOptions ) : Promise < Array < { name : string } > > ;
552+
547553 /** The name of the model */
548554 modelName : string ;
549555
You can’t perform that action at this time.
0 commit comments