hcengineering/platform · warning

No documents found to export

Error message

No documents found to export

What it means

The export job's completion check: after WorkspaceExporter.export runs, if exportResult.exportedCount === 0 the route responds 400 'No documents found to export'. This is not a crash — the export machinery worked but the query/class matched zero documents in the source workspace.

Source

Thrown at services/export/pod-export/src/server.ts:610

          const options: ExportOptions = {
            sourceWorkspace: wsIds,
            targetWorkspace: targetWsIds,
            sourceQuery: query ?? {},
            _class,
            conflictStrategy: conflictStrategy ?? 'duplicate',
            includeAttachments: includeAttachments ?? true,
            relations,
            fieldMappers,
            skipDeletedObsolete: skipDeletedObsolete ?? true,
            exportOnlyEffective: exportOnlyEffective ?? false,
            includeChildren: includeChildren ?? false,
            customHandlers: [createProductVersionHandler()]
          }

          const exportResult: ExportResult = await exporter.export(options)

          if (exportResult.exportedCount === 0) {
            res.status(400).send({ message: 'No documents found to export' })
          }

          if (exportResult.success) {
            await sendExportCompletionNotification(
              measureCtx,
              targetTxOps,
              targetWorkspace,
              targetWsIds,
              exportResult.exportedDocuments,
              wsIds,
              _class
            )
          }

          res.status(200).send({ message: 'Export completed' })
        } catch (err: any) {
          measureCtx.error('Export failed:', err)
          res.status(500).send({ message: 'Export failed', error: err.message ?? 'Unknown error' })

View on GitHub (pinned to 63e28dc964)

Solutions

  1. Verify the _class value matches a real class in the target workspace (check with the hierarchy client or dump).
  2. Relax or print the query filter to confirm it matches documents; remove the query first to test class-level export.
  3. Confirm the source workspace actually contains documents of that class (check via UI or API).
  4. Check for class/Ref renames after product upgrades and update the client.

Example fix

// before
await exportApi.export(token, { _class: 'contact:class:Contact ', query: { modifiedOn: { $gt: futureTs } } })
// after
await exportApi.export(token, { _class: 'contact:class:Contact' })
Defensive patterns

Strategy: validation

Validate before calling

// ensure the class exists and the query is not empty-limiting before export
const hierarchy = platformClient.getHierarchy()
if (!hierarchy.isDerived(_class, core.class.Doc)) throw new Error(`unknown _class: ${_class}`)
if (query && Object.keys(query).length > 0) {
  const count = await countDocs(_class, query)
  if (count === 0) console.warn('query matches no documents; export will 400')
}

Type guard

function hasExportableDocs(result: { exportedCount: number }): boolean {
  return result.exportedCount > 0
}

Try / catch

const res = await exportApi.exportToWorkspace(token, payload)
if (res.status === 400) {
  const body = await res.json()
  if (body.message === 'No documents found to export') {
    console.warn('nothing matched — check _class and query')
    return // not a hard failure
  }
}

Prevention

When it happens

Trigger: POSTing an export request whose _class, query filter, or attributesOnly options select no documents: wrong class ref, query that matches nothing, or exporting from a workspace/region with no data of that class.

Common situations: Typo or wrong Ref.* constant in _class, an overly restrictive query (e.g. filtering on a modified-since date in the future), exporting an empty/sandbox workspace, or class names that differ across product versions.

Related errors


AI-assisted analysis of hcengineering/platform@63e28dc964 (2026-08-29). Data as JSON: /api/errors/90291cc6de0d246f. Report an issue: GitHub.