Automattic/mongoose · error · MongooseError

bulkSave expects an array of documents to be passed, receive

Error message

bulkSave expects an array of documents to be passed, received `${documents}` instead

What it means

Error "bulkSave expects an array of documents to be passed, received `${documents}` instead" thrown in Automattic/mongoose.

Source

Thrown at lib/model.js:3926

  }

  return ret;
};

/**
 * Build bulk write operations for `bulkSave()`.
 *
 * @param {Document[]} documents The array of documents to build write operations of
 * @param {object} options
 * @param {boolean} options.skipValidation defaults to `false`, when set to true, building the write operations will bypass validating the documents.
 * @param {boolean} options.timestamps defaults to `null`, when set to false, mongoose will not add/update timestamps to the documents.
 * @return {Promise[]} Returns a array of all Promises the function executes to be awaited.
 * @api private
 */

Model.buildBulkWriteOperations = function buildBulkWriteOperations(documents, options) {
  if (!Array.isArray(documents)) {
    throw new MongooseError(`bulkSave expects an array of documents to be passed, received \`${documents}\` instead`);
  }

  setDefaultOptions();

  const writeOperations = documents.map((document, i) => {
    if (!options.skipValidation) {
      if (!(document instanceof Document)) {
        throw new MongooseError(`documents.${i} was not a mongoose document, documents must be an array of mongoose documents (instanceof mongoose.Document).`);
      }
      if (options.validateBeforeSave == null || options.validateBeforeSave) {
        const err = document.$__validateSync();
        if (err != null) {
          throw err;
        }
      }
    }

    const isANewDocument = document.isNew;

View on GitHub (pinned to 49cdab0136)

When it happens

Trigger: Thrown at lib/model.js:3926 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of Automattic/mongoose@49cdab0136 (2026-08-21). Data as JSON: /api/errors/f1eae68c6a86be72. Report an issue: GitHub.