function Aggregate(pipeline, modelOrConn) {
  this._pipeline = [];
  if (modelOrConn == null || modelOrConn[modelSymbol]) {
    this._model = modelOrConn;
  } else {
    this._connection = modelOrConn;
  }
  this.options = {};

  if (arguments.length === 1 && Array.isArray(pipeline)) {
    this.append.apply(this, pipeline);
  }
}
Aggregate constructor used for building aggregation pipelines. Do not
instantiate this class directly, use [Model.aggregate()](https://mongoosejs.com/docs/api/model.html#Model.aggregate()) instead.

#### Example:

    const aggregate = Model.aggregate([
      { $project: { a: 1, b: 1 } },
      { $skip: 5 }
    ]);

    Model.
      aggregate([{ $match: { age: { $gte: 21 }}}]).
      unwind('tags').
      exec();

#### Note:

- The documents returned are plain javascript objects, not mongoose documents (since any shape of document can be returned).
- Mongoose does **not** cast pipeline stages. The below will **not** work unless `_id` is a string in the database

    new Aggregate([{ $match: { _id: '00000000000000000000000a' } }]);
    // Do this instead to cast to an ObjectId
    new Aggregate([{ $match: { _id: new mongoose.Types.ObjectId('00000000000000000000000a') } }]);

@see MongoDB https://www.mongodb.com/docs/manual/applications/aggregation/
@see driver https://mongodb.github.io/node-mongodb-native/4.9/classes/Collection.html#aggregate
@param {Array} [pipeline] aggregation pipeline as an array of objects
@param {Model|Connection} [modelOrConn] the model or connection to use with this aggregate.
@api public