Automattic/mongoose · error · MongooseError

Must specify model in Connection.prototype.bulkWrite() opera

Error message

Must specify model in Connection.prototype.bulkWrite() operations

What it means

Error "Must specify model in Connection.prototype.bulkWrite() operations" thrown in Automattic/mongoose.

Source

Thrown at lib/connection.js:473

Connection.prototype.bulkWrite = async function bulkWrite(ops, options) {
  await this._waitForConnect();
  options = options || {};

  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 = [];

View on GitHub (pinned to 49cdab0136)

When it happens

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