From 848478a9ad6a7a7de508249f8cef127ae348af72 Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Mon, 26 May 2025 14:36:50 -0400 Subject: [PATCH 1/2] refactor: remove unnecessary async iterator checks --- lib/aggregate.js | 15 +++------------ lib/query.js | 19 +++++-------------- 2 files changed, 8 insertions(+), 26 deletions(-) diff --git a/lib/aggregate.js b/lib/aggregate.js index 8ad43f5b689..8dba993b086 100644 --- a/lib/aggregate.js +++ b/lib/aggregate.js @@ -1139,24 +1139,15 @@ Aggregate.prototype.finally = function(onFinally) { * console.log(doc.name); * } * - * Node.js 10.x supports async iterators natively without any flags. You can - * enable async iterators in Node.js 8.x using the [`--harmony_async_iteration` flag](https://github.com/tc39/proposal-async-iteration/issues/117#issuecomment-346695187). - * - * **Note:** This function is not set if `Symbol.asyncIterator` is undefined. If - * `Symbol.asyncIterator` is undefined, that means your Node.js version does not - * support async iterators. - * * @method [Symbol.asyncIterator] * @memberOf Aggregate * @instance * @api public */ -if (Symbol.asyncIterator != null) { - Aggregate.prototype[Symbol.asyncIterator] = function() { - return this.cursor({ useMongooseAggCursor: true }).transformNull()._transformForAsyncIterator(); - }; -} + Aggregate.prototype[Symbol.asyncIterator] = function() { + return this.cursor({ useMongooseAggCursor: true }).transformNull()._transformForAsyncIterator(); + }; /*! * Helpers diff --git a/lib/query.js b/lib/query.js index d8961e4b015..9a8be9c0259 100644 --- a/lib/query.js +++ b/lib/query.js @@ -5406,26 +5406,17 @@ Query.prototype.nearSphere = function() { * console.log(doc.name); * } * - * Node.js 10.x supports async iterators natively without any flags. You can - * enable async iterators in Node.js 8.x using the [`--harmony_async_iteration` flag](https://github.com/tc39/proposal-async-iteration/issues/117#issuecomment-346695187). - * - * **Note:** This function is not if `Symbol.asyncIterator` is undefined. If - * `Symbol.asyncIterator` is undefined, that means your Node.js version does not - * support async iterators. - * * @method [Symbol.asyncIterator] * @memberOf Query * @instance * @api public */ -if (Symbol.asyncIterator != null) { - Query.prototype[Symbol.asyncIterator] = function queryAsyncIterator() { - // Set so QueryCursor knows it should transform results for async iterators into `{ value, done }` syntax - this._mongooseOptions._asyncIterator = true; - return this.cursor(); - }; -} + Query.prototype[Symbol.asyncIterator] = function queryAsyncIterator() { + // Set so QueryCursor knows it should transform results for async iterators into `{ value, done }` syntax + this._mongooseOptions._asyncIterator = true; + return this.cursor(); + }; /** * Specifies a `$polygon` condition From 56137d488076005e8718d01eac0345637d93ba02 Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Mon, 26 May 2025 14:39:13 -0400 Subject: [PATCH 2/2] style: fix lint --- lib/aggregate.js | 6 +++--- lib/query.js | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/aggregate.js b/lib/aggregate.js index 8dba993b086..560c9e228c8 100644 --- a/lib/aggregate.js +++ b/lib/aggregate.js @@ -1145,9 +1145,9 @@ Aggregate.prototype.finally = function(onFinally) { * @api public */ - Aggregate.prototype[Symbol.asyncIterator] = function() { - return this.cursor({ useMongooseAggCursor: true }).transformNull()._transformForAsyncIterator(); - }; +Aggregate.prototype[Symbol.asyncIterator] = function() { + return this.cursor({ useMongooseAggCursor: true }).transformNull()._transformForAsyncIterator(); +}; /*! * Helpers diff --git a/lib/query.js b/lib/query.js index 9a8be9c0259..8f3702d0c11 100644 --- a/lib/query.js +++ b/lib/query.js @@ -5412,11 +5412,11 @@ Query.prototype.nearSphere = function() { * @api public */ - Query.prototype[Symbol.asyncIterator] = function queryAsyncIterator() { - // Set so QueryCursor knows it should transform results for async iterators into `{ value, done }` syntax - this._mongooseOptions._asyncIterator = true; - return this.cursor(); - }; +Query.prototype[Symbol.asyncIterator] = function queryAsyncIterator() { + // Set so QueryCursor knows it should transform results for async iterators into `{ value, done }` syntax + this._mongooseOptions._asyncIterator = true; + return this.cursor(); +}; /** * Specifies a `$polygon` condition