Automattic/mongoose · error · MongooseError
Model.aggregate() no longer accepts a callback
Error message
Model.aggregate() no longer accepts a callback
What it means
Error "Model.aggregate() no longer accepts a callback" thrown in Automattic/mongoose.
Source
Thrown at lib/model.js:4247
* #### More About Aggregations:
*
* - [Mongoose `Aggregate`](https://mongoosejs.com/docs/api/aggregate.html)
* - [An Introduction to Mongoose Aggregate](https://masteringjs.io/tutorials/mongoose/aggregate)
* - [MongoDB Aggregation docs](https://www.mongodb.com/docs/manual/applications/aggregation/)
*
* @see Aggregate https://mongoosejs.com/docs/api/aggregate.html#Aggregate()
* @see MongoDB https://www.mongodb.com/docs/manual/applications/aggregation/
* @param {Array} [pipeline] aggregation pipeline as an array of objects
* @param {object} [options] aggregation options
* @return {Aggregate}
* @api public
*/
Model.aggregate = function aggregate(pipeline, options) {
_checkContext(this, 'aggregate');
if (typeof options === 'function' || typeof arguments[2] === 'function') {
throw new MongooseError('Model.aggregate() no longer accepts a callback');
}
const aggregate = new Aggregate(pipeline || []);
aggregate.model(this);
if (options != null) {
aggregate.option(options);
}
return aggregate;
};
/**
* Casts and validates the given object against this model's schema, passing the
* given `context` to custom validators.
*
* #### Example:
*
* const Model = mongoose.model('Test', Schema({View on GitHub (pinned to 49cdab0136)
When it happens
Trigger: Thrown at lib/model.js:4247 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/3266c82d563db94d.
Report an issue: GitHub.