Automattic/mongoose · error · MongooseError

Must specify operation name in Connection.prototype.bulkWrit

Error message

Must specify operation name in Connection.prototype.bulkWrite()

What it means

Error "Must specify operation name in Connection.prototype.bulkWrite()" thrown in Automattic/mongoose.

Source

Thrown at lib/connection.js:478

  const ordered = options.ordered == null ? true : options.ordered;
  const asyncLocalStorage = this.base.transactionAsyncLocalStorage?.getStore();
  if ((!options || !Object.hasOwn(options, 'session')) && asyncLocalStorage?.session != null) {
    options = { ...options, session: asyncLocalStorage.session };
  }

  const now = this.base.now();

  let res = null;
  if (ordered) {
    const opsToSend = [];
    for (const op of ops) {
      if (typeof op.model !== 'string' && !op.model?.[modelSymbol]) {
        throw new MongooseError('Must specify model in Connection.prototype.bulkWrite() operations');
      }
      const Model = op.model[modelSymbol] ? op.model : this.model(op.model);

      if (op.name == null) {
        throw new MongooseError('Must specify operation name in Connection.prototype.bulkWrite()');
      }
      if (!Object.hasOwn(castBulkWrite.cast, op.name)) {
        throw new MongooseError(`Unrecognized bulkWrite() operation name ${op.name}`);
      }

      await castBulkWrite.cast[op.name](Model, op, options, now);
      opsToSend.push({ ...op, namespace: Model.namespace() });
    }

    res = await this.client.bulkWrite(opsToSend, options);
  } else {
    const validOps = [];
    const validOpIndexes = [];
    let validationErrors = [];
    const asyncValidations = [];
    const results = [];
    for (let i = 0; i < ops.length; ++i) {
      const op = ops[i];

View on GitHub (pinned to 49cdab0136)

When it happens

Trigger: Thrown at lib/connection.js:478 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/6d5bbcef384fe84a. Report an issue: GitHub.