{"record":{"id":"d383a48de6f56d4f","repo":"Mintplex-Labs/anything-llm","slug":"could-not-find-a-document-by-id-docid","errorCode":null,"errorMessage":"Could not find a document by id ${docId}","messagePattern":"Could not find a document by id (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/models/documents.js","lineNumber":289,"sourceCode":"      return { document: null, message: error.message };\n    }\n  },\n  _updateAll: async function (clause = {}, data = {}) {\n    try {\n      await prisma.workspace_documents.updateMany({\n        where: clause,\n        data,\n      });\n      return true;\n    } catch (error) {\n      console.error(error.message);\n      return false;\n    }\n  },\n  content: async function (docId) {\n    if (!docId) throw new Error(\"No workspace docId provided!\");\n    const document = await this.get({ docId: String(docId) });\n    if (!document) throw new Error(`Could not find a document by id ${docId}`);\n\n    const { fileData } = require(\"../utils/files\");\n    const data = await fileData(document.docpath);\n    return { title: data.title, content: data.pageContent };\n  },\n  contentByDocPath: async function (docPath) {\n    const { fileData } = require(\"../utils/files\");\n    const data = await fileData(docPath);\n    return { title: data.title, content: data.pageContent };\n  },\n\n  // Some data sources have encoded params in them we don't want to log - so strip those details.\n  _stripSource: function (sourceString, type) {\n    if ([\"confluence\", \"github\"].includes(type)) {\n      const _src = new URL(sourceString);\n      _src.search = \"\"; // remove all search params that are encoded for resync.\n      return _src.toString();\n    }","sourceCodeStart":271,"sourceCodeEnd":307,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/server/models/documents.js#L271-L307","documentation":"Thrown by the Document model's content(docId) helper after its internal lookup `this.get({ docId: String(docId) })` returns no row. The docId supplied has no matching record in the `documents` table, so the server cannot resolve the docpath needed to read the file. It is a data-level lookup failure, not a filesystem error - the underlying file may still exist on disk.","triggerScenarios":"Calling Documents.content(docId) with an ID that was deleted (workspace reset, document removal), a docId copied from another instance or database, or a non-string value that String() mangles (e.g. an object becoming '[object Object]') so the where-clause matches nothing.","commonSituations":"Stale document references in cached chat citations or frontend state after re-embedding; scripts iterating document IDs saved before a migration or reset; confusing the vector-store identifier with the documents.docId column.","solutions":["Verify the document still exists before reading content: `const doc = await Document.get({ docId }); if (!doc) ...`","If the document was deleted, re-upload or re-sync it so a new row (and new docId) is created","Refresh the stale reference (cached chat sources, saved job output) so it carries the current docId","If you already hold a valid file path, call Documents.contentByDocPath(docPath) instead"],"exampleFix":"// before\nconst { title, content } = await Document.content(docId);\n\n// after\nconst document = await Document.get({ docId: String(docId) });\nif (!document) throw new Error(`Document ${docId} no longer exists`);\nconst { title, content } = await Document.content(document.docId);","handlingStrategy":"validation","validationCode":"const { Document } = require('../models/documents');\n\nasync function assertDocumentExists(docId) {\n  if (typeof docId !== 'string' || docId.length === 0) return false;\n  const doc = await Document.get({ docId });\n  return doc !== null;\n}\n\nif (!(await assertDocumentExists(docId))) {\n  return res.status(404).json({ error: 'Document not found' });\n}","typeGuard":null,"tryCatchPattern":"try {\n  const data = await Document.content(docId);\n} catch (err) {\n  if (/Could not find a document by id/.test(err.message)) {\n    // missing resource: return 404, skip, or re-sync the stale reference\n  } else throw err;\n}","preventionTips":["Resolve documents through Document.get before dereferencing any docId received from clients or caches","Invalidate cached docIds (chat citations, saved job output) whenever workspaces are reset or re-embedded","Coerce and validate docId is a non-empty string before passing it in"],"tags":["documents","lookup","anythingllm","prisma"],"backgroundTag":"record-not-found","analyzedSha":"3aec848f2885144aa8f1e53b9731a04310d5d558","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}