Mintplex-Labs/anything-llm · error
Could not find a document by id ${docId}
Error message
Could not find a document by id ${docId} What it means
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.
Source
Thrown at server/models/documents.js:289
return { document: null, message: error.message };
}
},
_updateAll: async function (clause = {}, data = {}) {
try {
await prisma.workspace_documents.updateMany({
where: clause,
data,
});
return true;
} catch (error) {
console.error(error.message);
return false;
}
},
content: async function (docId) {
if (!docId) throw new Error("No workspace docId provided!");
const document = await this.get({ docId: String(docId) });
if (!document) throw new Error(`Could not find a document by id ${docId}`);
const { fileData } = require("../utils/files");
const data = await fileData(document.docpath);
return { title: data.title, content: data.pageContent };
},
contentByDocPath: async function (docPath) {
const { fileData } = require("../utils/files");
const data = await fileData(docPath);
return { title: data.title, content: data.pageContent };
},
// Some data sources have encoded params in them we don't want to log - so strip those details.
_stripSource: function (sourceString, type) {
if (["confluence", "github"].includes(type)) {
const _src = new URL(sourceString);
_src.search = ""; // remove all search params that are encoded for resync.
return _src.toString();
}View on GitHub (pinned to 3aec848f28)
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
Example fix
// before
const { title, content } = await Document.content(docId);
// after
const document = await Document.get({ docId: String(docId) });
if (!document) throw new Error(`Document ${docId} no longer exists`);
const { title, content } = await Document.content(document.docId); Defensive patterns
Strategy: validation
Validate before calling
const { Document } = require('../models/documents');
async function assertDocumentExists(docId) {
if (typeof docId !== 'string' || docId.length === 0) return false;
const doc = await Document.get({ docId });
return doc !== null;
}
if (!(await assertDocumentExists(docId))) {
return res.status(404).json({ error: 'Document not found' });
} Try / catch
try {
const data = await Document.content(docId);
} catch (err) {
if (/Could not find a document by id/.test(err.message)) {
// missing resource: return 404, skip, or re-sync the stale reference
} else throw err;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.
Related errors
- Invalid path name
- Invalid folder name.
- Run not found
- System prompt variable not found
- Internal Server Error
AI-assisted analysis of Mintplex-Labs/anything-llm@3aec848f28 (2026-08-18).
Data as JSON: /api/errors/d383a48de6f56d4f.
Report an issue: GitHub.