{"record":{"id":"551210ba23610d5d","repo":"payloadcms/payload","slug":"import-file-contains-documents-length-documents","errorCode":null,"errorMessage":"Import file contains ${documents.length} documents but limit is ${maxLimit}","messagePattern":"Import file contains (.+?) documents but limit is (.+?)","errorType":"http","errorClass":"APIError","httpStatus":400,"severity":"error","filePath":"packages/plugin-import-export/src/import/createImport.ts","lineNumber":197,"sourceCode":"      }),\n    )\n  }\n\n  if (debug) {\n    req.payload.logger.debug({\n      msg: `Parsed ${documents.length} documents from ${format} file`,\n    })\n    if (documents.length > 0) {\n      req.payload.logger.debug({\n        doc: documents[0],\n        msg: 'First document sample:',\n      })\n    }\n  }\n\n  // Enforce maxLimit before processing to save memory/time\n  if (typeof maxLimit === 'number' && maxLimit > 0 && documents.length > maxLimit) {\n    throw new APIError(\n      `Import file contains ${documents.length} documents but limit is ${maxLimit}`,\n      400,\n      null,\n      true,\n    )\n  }\n\n  // Remove disabled fields from all documents\n  if (disabledFields.length > 0) {\n    documents = documents.map((doc) => removeDisabledFields(doc, disabledFields))\n  }\n\n  if (debug) {\n    req.payload.logger.debug({\n      batchSize,\n      documentCount: documents.length,\n      msg: 'Processing import in batches',\n    })","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/plugin-import-export/src/import/createImport.ts#L179-L215","documentation":"After parsing, createImport enforces an upper bound on document count via the resolved maxLimit (from plugin importLimit). If documents.length exceeds maxLimit it throws 400 before processing, deliberately to save memory and time on oversized imports.","triggerScenarios":"Uploading a CSV/JSON with more rows/documents than the configured importLimit. maxLimit is a positive number resolved from the plugin config and passed into createImport.","commonSituations":"importLimit left at a low default while real files have thousands of rows; a one-off bulk import exceeds the steady-state cap; limit lowered without communicating to data owners.","solutions":["Raise importLimit in the plugin-import-export config for the collection/global.","Split the source file into chunks under maxLimit and import each separately.","Pre-filter rows in the source so the parsed count stays under the limit."],"exampleFix":"// before: importLimit too low\nimportExportPlugin({ collections: { posts: { importLimit: 100 } } })\n// after\nimportExportPlugin({ collections: { posts: { importLimit: 10000 } } })","handlingStrategy":"validation","validationCode":"function chunkDocuments<T>(docs: T[], maxLimit: number): T[][] {\n  if (docs.length > maxLimit) {\n    // split instead of failing\n  }\n  const chunks: T[][] = []\n  for (let i = 0; i < docs.length; i += maxLimit) chunks.push(docs.slice(i, i + maxLimit))\n  return chunks\n}\n\n// parse once, then import each chunk under the limit","typeGuard":null,"tryCatchPattern":"try {\n  await createImport({ ..., maxLimit })\n} catch (err) {\n  if (err instanceof APIError && /limit is/.test(err.message)) {\n    // split the source file and retry each chunk\n  } else throw err\n}","preventionTips":["Set importLimit high enough for realistic bulk imports.","Pre-count rows in the source file before uploading.","Document the limit to data owners so they chunk large files."],"tags":["import","limits","plugin-import-export"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}