diff --git a/lib/connection.js b/lib/connection.js index 1b1d6bdff0..b4be11f5c1 100644 --- a/lib/connection.js +++ b/lib/connection.js @@ -68,7 +68,7 @@ function Connection(base) { this.models = {}; this.config = {}; this.replica = false; - this.options = null; + this.options = Object.assign({}, base.options); this.otherDbs = []; // FIXME: To be replaced with relatedDbs this.relatedDbs = {}; // Hashmap of other dbs that share underlying connection this.states = STATES; @@ -1781,6 +1781,19 @@ Connection.prototype.syncIndexes = async function syncIndexes(options = {}) { return result; }; +/** + * Runs a [db-level aggregate()](https://www.mongodb.com/docs/manual/reference/method/db.aggregate/) on this connection's underlying `db` + * + * @param {Array} pipeline + * @param {Object} [options] + * @return {Aggregate} Aggregation wrapper + * @api public + */ + +Connection.prototype.aggregate = function aggregate(pipeline, options) { + return new this.base.Aggregate(null, this).append(pipeline).option(options ?? {}); +}; + /** * Switches to a different database using the same [connection pool](https://mongoosejs.com/docs/api/connectionshtml#connection_pools). * diff --git a/package.json b/package.json index ecae8b6674..a852e3abfd 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "bson": "^6.10.4", "kareem": "2.6.3", "mongodb": "~6.20.0", + "mongoose": "^8.20.0", "mpath": "0.9.0", "mquery": "5.0.0", "ms": "2.1.3",