Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix aggregate cursor als #15094

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions lib/aggregate.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,24 @@ function Aggregate(pipeline, model) {

Aggregate.prototype.options;

/**
* Returns default options for this aggregate.
*
* @param {Model} model
* @api private
*/

Aggregate.prototype._optionsForExec = function() {
const options = this.options || {};

const asyncLocalStorage = this.model()?.db?.base.transactionAsyncLocalStorage?.getStore();
if (!options.hasOwnProperty('session') && asyncLocalStorage?.session != null) {
options.session = asyncLocalStorage.session;
}

return options;
};

/**
* Get/set the model that this aggregation will execute on.
*
Expand Down Expand Up @@ -914,6 +932,7 @@ Aggregate.prototype.option = function(value) {
*/

Aggregate.prototype.cursor = function(options) {
this._optionsForExec();
this.options.cursor = options || {};
return new AggregationCursor(this); // return this;
};
Expand Down Expand Up @@ -1022,10 +1041,7 @@ Aggregate.prototype.exec = async function exec() {
applyGlobalMaxTimeMS(this.options, model.db.options, model.base.options);
applyGlobalDiskUse(this.options, model.db.options, model.base.options);

const asyncLocalStorage = this.model()?.db?.base.transactionAsyncLocalStorage?.getStore();
if (!this.options.hasOwnProperty('session') && asyncLocalStorage?.session != null) {
this.options.session = asyncLocalStorage.session;
}
this._optionsForExec();

if (this.options && this.options.cursor) {
return new AggregationCursor(this);
Expand All @@ -1052,6 +1068,7 @@ Aggregate.prototype.exec = async function exec() {
}

const options = clone(this.options || {});

let result;
try {
const cursor = await collection.aggregate(this._pipeline, options);
Expand Down