diff --git a/test/integration/crud/aggregation.test.ts b/test/integration/crud/aggregation.test.ts index 7352bafcd0..6041f5a02a 100644 --- a/test/integration/crud/aggregation.test.ts +++ b/test/integration/crud/aggregation.test.ts @@ -270,66 +270,70 @@ describe('Aggregation', function () { }); }); - it('should correctly return a cursor and call explain', function (done) { - const client = this.configuration.newClient({ maxPoolSize: 1 }), - databaseName = this.configuration.db; - - const db = client.db(databaseName); - // Some docs for insertion - const docs = [ - { - title: 'this is my title', - author: 'bob', - posted: new Date(), - pageViews: 5, - tags: ['fun', 'good', 'fun'], - other: { foo: 5 }, - comments: [ - { author: 'joe', text: 'this is cool' }, - { author: 'sam', text: 'this is bad' } - ] - } - ]; + it( + 'should correctly return a cursor and call explain', + { requires: { mongodb: '<7.1.0' } }, + function (done) { + const client = this.configuration.newClient({ maxPoolSize: 1 }), + databaseName = this.configuration.db; + + const db = client.db(databaseName); + // Some docs for insertion + const docs = [ + { + title: 'this is my title', + author: 'bob', + posted: new Date(), + pageViews: 5, + tags: ['fun', 'good', 'fun'], + other: { foo: 5 }, + comments: [ + { author: 'joe', text: 'this is cool' }, + { author: 'sam', text: 'this is bad' } + ] + } + ]; - // Create a collection - const collection = db.collection('shouldCorrectlyDoAggWithCursorGet'); - // Insert the docs - collection.insertMany(docs, { writeConcern: { w: 1 } }, function (err, result) { - expect(result).to.exist; - expect(err).to.not.exist; + // Create a collection + const collection = db.collection('shouldCorrectlyDoAggWithCursorGet'); + // Insert the docs + collection.insertMany(docs, { writeConcern: { w: 1 } }, function (err, result) { + expect(result).to.exist; + expect(err).to.not.exist; - // Execute aggregate, notice the pipeline is expressed as an Array - const cursor = collection.aggregate( - [ - { - $project: { - author: 1, - tags: 1 + // Execute aggregate, notice the pipeline is expressed as an Array + const cursor = collection.aggregate( + [ + { + $project: { + author: 1, + tags: 1 + } + }, + { $unwind: '$tags' }, + { + $group: { + _id: { tags: '$tags' }, + authors: { $addToSet: '$author' } + } } - }, - { $unwind: '$tags' }, + ], { - $group: { - _id: { tags: '$tags' }, - authors: { $addToSet: '$author' } - } + cursor: { batchSize: 100 } } - ], - { - cursor: { batchSize: 100 } - } - ); + ); - // Iterate over all the items in the cursor - cursor.explain(function (err, result) { - expect(err).to.not.exist; - expect(result.stages).to.have.lengthOf.at.least(1); - expect(result.stages[0]).to.have.property('$cursor'); + // Iterate over all the items in the cursor + cursor.explain(function (err, result) { + expect(err).to.not.exist; + expect(result.stages).to.have.lengthOf.at.least(1); + expect(result.stages[0]).to.have.property('$cursor'); - client.close(done); + client.close(done); + }); }); - }); - }); + } + ).skipReason = 'TODO(NODE-5617): aggregate explain tests failing on latest servers'; it('should correctly return a cursor with batchSize 1 and call next', function (done) { const client = this.configuration.newClient({ w: 1 }, { maxPoolSize: 1 }), diff --git a/test/integration/crud/explain.test.ts b/test/integration/crud/explain.test.ts index 9961fd1a7e..82c259edea 100644 --- a/test/integration/crud/explain.test.ts +++ b/test/integration/crud/explain.test.ts @@ -1,5 +1,6 @@ import { expect } from 'chai'; import { once } from 'events'; +import { gte } from 'semver'; import { type Collection, @@ -73,6 +74,17 @@ describe('CRUD API explain option', function () { collection = db.collection('test'); await collection.insertOne({ a: 1 }); commandStartedPromise = once(client, 'commandStarted'); + + const test = this.currentTest; + if ( + test?.fullTitle().includes('aggregate') && + gte(this.configuration.version, '7.1.0') && + this.currentTest + ) { + this.currentTest.skipReason = + 'TODO(NODE-5617): aggregate explain tests failing on latest servers'; + this.skip(); + } }); afterEach(async function () {