overleaf/overleaf · error · NotFoundError

No such doc: ${docId} in project ${projectId}

Error message

No such doc: ${docId} in project ${projectId}

What it means

NotFoundError thrown by DocManager._getDoc when MongoManager.findDoc returns null — no doc with that docId exists in the given project. The caller (e.g. getDoc/getFullDoc) requires an existing document to read lines and metadata. It is the canonical 'document does not exist' signal of docstore.

Source

Thrown at services/docstore/app/js/DocManager.js:35

  /**
   * @param {string} projectId
   * @param {string} docId
   * @param {{inS3: boolean}} filter
   * @returns {Promise<WithId<Document>>}
   * @private
   */
  async _getDoc(projectId, docId, filter) {
    if (filter == null) {
      filter = {}
    }
    if (filter.inS3 !== true) {
      throw new Error('must include inS3 when getting doc')
    }

    const doc = await MongoManager.findDoc(projectId, docId, filter)

    if (doc == null) {
      throw new Errors.NotFoundError(
        `No such doc: ${docId} in project ${projectId}`
      )
    }

    if (doc.inS3) {
      await DocArchive.unarchiveDoc(projectId, docId)
      return await DocManager._getDoc(projectId, docId, filter)
    }

    if (filter.ranges) {
      RangeManager.fixCommentIds(doc)
    }

    return doc
  },

  async isDocDeleted(projectId, docId) {
    const doc = await MongoManager.findDoc(projectId, docId, {

View on GitHub (pinned to 28ad3b03b7)

Solutions

  1. Verify the projectId/docId pair exists (e.g. via getAllDocs) before reading
  2. Treat as 404 upstream and refresh the client's doc list
  3. Re-create or restore the doc if it was deleted unintentionally
  4. Check that the caller passes the correct ObjectId (not a string from another project)
Defensive patterns

Strategy: try-catch

Validate before calling

// verify doc exists before reading
const docs = await docstore.getAllDocs(projectId)
if (!docs.some(d => String(d._id) === String(docId))) return { status: 'missing-doc' }

Type guard

function isDocNotFound(e) { return e && e.name === 'NotFoundError' && /No such doc/.test(e.message) }

Try / catch

try { return await getDoc(projectId, docId) } catch (e) { if (isDocNotFound(e)) return handleMissingDoc(projectId, docId); throw e }

Prevention

When it happens

Trigger: getDoc/getFullDoc called with a docId not present in the project's docs collection; typo'd or truncated ObjectId; doc already deleted but still referenced.

Common situations: Stale client references after a doc was deleted; race between deletion and read; mismatched projectId/docId pair from a broken URL or sync bug; forgetting inS3 handling is unrelated — null doc alone triggers this.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of overleaf/overleaf@28ad3b03b7 (2026-09-03). Data as JSON: /api/errors/1aec2b196927b08f. Report an issue: GitHub.