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

Function constructIndexDescriptionMap

src/operations/indexes.ts:174–198  ·  view source on GitHub ↗

* Converts an `IndexSpecification`, which can be specified in multiple formats, into a * valid `key` for the createIndexes command.

(indexSpec: IndexSpecification)

Source from the content-addressed store, hash-verified

172 * valid `key` for the createIndexes command.
173 */
174function constructIndexDescriptionMap(indexSpec: IndexSpecification): Map<string, IndexDirection> {
175 const key: Map<string, IndexDirection> = new Map();
176
177 const indexSpecs =
178 !Array.isArray(indexSpec) || isSingleIndexTuple(indexSpec) ? [indexSpec] : indexSpec;
179
180 // Iterate through array and handle different types
181 for (const spec of indexSpecs) {
182 if (typeof spec === 'string') {
183 key.set(spec, 1);
184 } else if (Array.isArray(spec)) {
185 key.set(spec[0], spec[1] ?? 1);
186 } else if (spec instanceof Map) {
187 for (const [property, value] of spec) {
188 key.set(property, value);
189 }
190 } else if (isObject(spec)) {
191 for (const [property, value] of Object.entries(spec)) {
192 key.set(property, value);
193 }
194 }
195 }
196
197 return key;
198}
199
200/**
201 * Receives an index description and returns a modified index description which has had invalid options removed

Callers 1

Calls 3

isObjectFunction · 0.90
isSingleIndexTupleFunction · 0.85
setMethod · 0.80

Tested by

no test coverage detected