{"record":{"id":"948b686b64a8150b","repo":"Automattic/mongoose","slug":"documents-i-was-not-a-mongoose-document-docume","errorCode":null,"errorMessage":"documents.${i} was not a mongoose document, documents must be an array of mongoose documents (instanceof mongoose.Document).","messagePattern":"documents\\.(.+?) was not a mongoose document, documents must be an array of mongoose documents \\(instanceof mongoose\\.Document\\)\\.","errorType":"exception","errorClass":"MongooseError","httpStatus":null,"severity":"error","filePath":"lib/model.js","lineNumber":3934,"sourceCode":" * @param {Document[]} documents The array of documents to build write operations of\n * @param {object} options\n * @param {boolean} options.skipValidation defaults to `false`, when set to true, building the write operations will bypass validating the documents.\n * @param {boolean} options.timestamps defaults to `null`, when set to false, mongoose will not add/update timestamps to the documents.\n * @return {Promise[]} Returns a array of all Promises the function executes to be awaited.\n * @api private\n */\n\nModel.buildBulkWriteOperations = function buildBulkWriteOperations(documents, options) {\n  if (!Array.isArray(documents)) {\n    throw new MongooseError(`bulkSave expects an array of documents to be passed, received \\`${documents}\\` instead`);\n  }\n\n  setDefaultOptions();\n\n  const writeOperations = documents.map((document, i) => {\n    if (!options.skipValidation) {\n      if (!(document instanceof Document)) {\n        throw new MongooseError(`documents.${i} was not a mongoose document, documents must be an array of mongoose documents (instanceof mongoose.Document).`);\n      }\n      if (options.validateBeforeSave == null || options.validateBeforeSave) {\n        const err = document.$__validateSync();\n        if (err != null) {\n          throw err;\n        }\n      }\n    }\n\n    const isANewDocument = document.isNew;\n    if (isANewDocument) {\n      // Like `$__version()` on insert, initialize the version key so\n      // inserted documents get the same shape as `save()` gives them\n      const versionKey = document.$__schema.options.versionKey;\n      if (versionKey) {\n        document.$__setValue(versionKey, 0);\n      }\n      const writeOperation = { insertOne: { document } };","sourceCodeStart":3916,"sourceCodeEnd":3952,"githubUrl":"https://github.com/Automattic/mongoose/blob/49cdab01366679723b487ecb754b38570f783289/lib/model.js#L3916-L3952","documentation":"Error \"documents.${i} was not a mongoose document, documents must be an array of mongoose documents (instanceof mongoose.Document).\" thrown in Automattic/mongoose.","triggerScenarios":"Thrown at lib/model.js:3934 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"49cdab01366679723b487ecb754b38570f783289","analyzedAt":"2026-08-21T22:54:00.882Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}