MCPcopy
hub / github.com/mongodb/node-mongodb-native / indexExists

Method indexExists

src/collection.ts:749–757  ·  view source on GitHub ↗

* Checks if one or more indexes exist on the collection, fails on first non-existing index * * @param indexes - One or more index names to check. * @param options - Optional settings for the command

(indexes: string | string[], options?: ListIndexesOptions)

Source from the content-addressed store, hash-verified

747 * @param options - Optional settings for the command
748 */
749 async indexExists(indexes: string | string[], options?: ListIndexesOptions): Promise<boolean> {
750 const indexNames: string[] = Array.isArray(indexes) ? indexes : [indexes];
751 const allIndexes: Set<string> = new Set(
752 await this.listIndexes(options)
753 .map(({ name }) => name)
754 .toArray()
755 );
756 return indexNames.every(name => allIndexes.has(name));
757 }
758
759 /**
760 * Retrieves this collections index info.

Calls 4

listIndexesMethod · 0.95
toArrayMethod · 0.80
mapMethod · 0.45
hasMethod · 0.45

Tested by

no test coverage detected