{"record":{"id":"ba5087e1d5cb1a77","repo":"FlowiseAI/Flowise","slug":"if-provided-options-ids-must-be-an-array-with-t","errorCode":null,"errorMessage":"If provided, \"options.ids\" must be an array with the same length as \"vectors\".","messagePattern":"If provided, \"options\\.ids\" must be an array with the same length as \"vectors\"\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/components/nodes/vectorstores/MongoDBAtlas/core.ts","lineNumber":83,"sourceCode":"    }\n\n    async closeConnection(client: MongoClient) {\n        await client.close()\n    }\n\n    async addVectors(vectors: number[][], documents: Document[], options?: { ids?: string[] }) {\n        const client = await this.getClient()\n        const collection = client.db(this.connectionDetails.databaseName).collection(this.connectionDetails.collectionName)\n        const docs = vectors.map((embedding, idx) => ({\n            [this.textKey]: documents[idx].pageContent,\n            [this.embeddingKey]: embedding,\n            ...documents[idx].metadata\n        }))\n        if (options?.ids === undefined) {\n            await collection.insertMany(docs)\n        } else {\n            if (options.ids.length !== vectors.length) {\n                throw new Error(`If provided, \"options.ids\" must be an array with the same length as \"vectors\".`)\n            }\n            const { ids } = options\n            for (let i = 0; i < docs.length; i += 1) {\n                await this.caller.call(async () => {\n                    await collection.updateOne(\n                        { [this.primaryKey]: ids[i] },\n                        { $set: { [this.primaryKey]: ids[i], ...docs[i] } },\n                        { upsert: true }\n                    )\n                })\n            }\n        }\n        await this.closeConnection(client)\n        return options?.ids ?? docs.map((doc) => doc[this.primaryKey])\n    }\n\n    async addDocuments(documents: Document[], options?: { ids?: string[] }) {\n        const texts = documents.map(({ pageContent }) => pageContent)","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/components/nodes/vectorstores/MongoDBAtlas/core.ts#L65-L101","documentation":"Thrown by `MongoDBAtlasVectorSearch.addVectors` when the caller supplies `options.ids` whose length does not equal `vectors.length`. When ids are provided, the store upserts each document keyed by id, so a length mismatch would silently misalign documents and ids — the guard refuses this rather than corrupt data.","triggerScenarios":"Passing a partial `ids` array (e.g. from a record manager that only tracked some documents), reusing an old ids array after the document list changed length, or off-by-one slicing of ids.","commonSituations":"Record-manager-driven upsert where `listKeys` returned fewer keys than the documents being re-indexed; caller computed ids from a filtered subset; concurrency added/removed documents between computing ids and calling addVectors.","solutions":["Ensure `options.ids.length === documents.length === vectors.length` before calling.","If only some documents have ids, omit `options.ids` entirely to use insertMany, or split into id-bearing and id-less batches.","Regenerate ids from the current documents array immediately before the call.","Add a unit assertion on the three lengths."],"exampleFix":"// before\nawait store.addVectors(vectors, docs, { ids: someKeys })\n// after — guard lengths up front\nif (ids && ids.length !== docs.length) {\n    throw new Error(`ids length ${ids.length} != docs length ${docs.length}`)\n}\nawait store.addVectors(vectors, docs, ids ? { ids } : undefined)","handlingStrategy":"type-guard","validationCode":"function assertIdsAligned(vectors: unknown[], docs: unknown[], ids?: string[]) {\n  if (vectors.length !== docs.length) throw new Error(`vectors (${vectors.length}) != docs (${docs.length})`)\n  if (ids !== undefined && ids.length !== vectors.length) {\n    throw new Error(`ids (${ids.length}) != vectors (${vectors.length})`)\n  }\n}","typeGuard":"function idsMatchLength(ids: string[] | undefined, n: number): ids is string[] {\n  return Array.isArray(ids) && ids.length === n\n}","tryCatchPattern":"try {\n  assertIdsAligned(vectors, documents, options?.ids)\n  await store.addVectors(vectors, documents, options)\n} catch (e) {\n  throw e instanceof Error ? e : new Error(String(e))\n}","preventionTips":["Compute ids from the current documents array immediately before the call.","If only some docs have ids, split into id-bearing and id-less batches.","Add a unit test asserting the three lengths are equal.","Never reuse stale id arrays after the document list mutates."],"tags":["mongodb-atlas","validation","upsert","data-integrity"],"backgroundTag":null,"analyzedSha":"abe4a8601a058047b350c260676826e21dd14101","analyzedAt":"2026-08-12T16:04:40.823Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}