diff --git a/src/cursor/cursor.ts b/src/cursor/cursor.ts index 86087039c4..69e7b420d4 100644 --- a/src/cursor/cursor.ts +++ b/src/cursor/cursor.ts @@ -1,6 +1,6 @@ import { emitDeprecatedOptionWarning } from '../utils'; import { ReadPreference, ReadPreferenceLike } from '../read_preference'; -import { Transform, PassThrough, Readable } from 'stream'; +import { Readable } from 'stream'; import { deprecate } from 'util'; import { MongoError, AnyError } from '../error'; import { @@ -886,32 +886,9 @@ export class Cursor< /** Return a modified Readable stream including a possible transform method. */ stream(options?: CursorStreamOptions): CursorStream { - // TODO: replace this method with transformStream in next major release return new CursorStream(this, options); } - /** - * Return a modified Readable stream that applies a given transform function, if supplied. If none supplied, - * returns a stream of unmodified docs. - */ - transformStream(options?: CursorStreamOptions): Transform { - const streamOptions: typeof options = options || {}; - if (typeof streamOptions.transform === 'function') { - const stream = new Transform({ - objectMode: true, - transform(chunk, encoding, callback) { - if (streamOptions.transform) { - this.push(streamOptions.transform(chunk)); - } - callback(); - } - }); - return this.stream().pipe(stream); - } - - return this.stream(options).pipe(new PassThrough({ objectMode: true })); - } - /** * Execute the explain for the cursor * diff --git a/test/functional/cursor.test.js b/test/functional/cursor.test.js index fc16bf5153..b71bacf265 100644 --- a/test/functional/cursor.test.js +++ b/test/functional/cursor.test.js @@ -4121,7 +4121,7 @@ describe('Cursor', function () { .then(() => collection.insertMany(docs)) .then(() => { cursor = collection.find(); - return cursor.transformStream(transformParam); + return cursor.stream(transformParam); }) .then(stream => { stream.on('data', function (doc) { @@ -4141,7 +4141,7 @@ describe('Cursor', function () { }); }; - it('transformStream should apply the supplied transformation function to each document in the stream', function (done) { + it('stream should apply the supplied transformation function to each document in the stream', function (done) { const configuration = this.configuration; const client = configuration.newClient({ w: 1 }, { poolSize: 1, auto_reconnect: false }); const expectedDocs = [ @@ -4152,7 +4152,7 @@ describe('Cursor', function () { const config = { client: client, configuration: configuration, - collectionName: 'transformStream-test-transform', + collectionName: 'stream-test-transform', transformFunc: doc => ({ _id: doc._id, b: doc.a.b, c: doc.a.c }), expectedSet: new Set(expectedDocs) }; @@ -4160,7 +4160,7 @@ describe('Cursor', function () { testTransformStream(config, done); }); - it('transformStream should return a stream of unmodified docs if no transform function applied', function (done) { + it('stream should return a stream of unmodified docs if no transform function applied', function (done) { const configuration = this.configuration; const client = configuration.newClient({ w: 1 }, { poolSize: 1, auto_reconnect: false }); const expectedDocs = [