Skip to content

Commit 9dee21f

Browse files
authored
feat: remove parallelCollectionScan helper
This command was deprecated in 4.2, and provides no actual benefit for users on WiredTiger. NODE-2713
1 parent da1b889 commit 9dee21f

9 files changed

+4
-730
lines changed

src/collection.ts

+1-56
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,7 @@ import ChangeStream = require('./change_stream');
2222
import WriteConcern = require('./write_concern');
2323
import ReadConcern = require('./read_concern');
2424
import { AggregationCursor, CommandCursor } from './cursor';
25-
import {
26-
ensureIndex,
27-
group,
28-
parallelCollectionScan,
29-
save,
30-
checkForAtomicOperators
31-
} from './operations/collection_ops';
25+
import { ensureIndex, group, save, checkForAtomicOperators } from './operations/collection_ops';
3226
import { removeDocuments, updateDocuments } from './operations/common_functions';
3327
import AggregateOperation = require('./operations/aggregate');
3428
import BulkWriteOperation = require('./operations/bulk_write');
@@ -75,7 +69,6 @@ interface Collection {
7569
ensureIndex(fieldOrSpec: any, options: any, callback: any): void;
7670
count(query: any, options: any, callback: any): void;
7771
findAndRemove(query: any, sort: any, options: any, callback: any): void;
78-
parallelCollectionScan(options: any, callback: any): void;
7972
group(
8073
keys: any,
8174
condition: any,
@@ -2131,54 +2124,6 @@ Collection.prototype.findAndRemove = deprecate(function(
21312124
},
21322125
'collection.findAndRemove is deprecated. Use findOneAndDelete instead.');
21332126

2134-
/**
2135-
* The callback format for results
2136-
*
2137-
* @callback Collection~parallelCollectionScanCallback
2138-
* @param {MongoError} error An error instance representing the error during the execution.
2139-
* @param {Cursor[]} cursors A list of cursors returned allowing for parallel reading of collection.
2140-
*/
2141-
2142-
/**
2143-
* Return N number of parallel cursors for a collection allowing parallel reading of entire collection. There are
2144-
* no ordering guarantees for returned results.
2145-
*
2146-
* @function
2147-
* @param {object} [options] Optional settings.
2148-
* @param {(ReadPreference|string)} [options.readPreference] The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
2149-
* @param {number} [options.batchSize=1000] Set the batchSize for the getMoreCommand when iterating over the query results.
2150-
* @param {number} [options.numCursors=1] The maximum number of parallel command cursors to return (the number of returned cursors will be in the range 1:numCursors)
2151-
* @param {boolean} [options.raw=false] Return all BSON documents as Raw Buffer documents.
2152-
* @param {Collection~parallelCollectionScanCallback} [callback] The command result callback
2153-
* @returns {Promise<void>} returns Promise if no callback passed
2154-
*/
2155-
Collection.prototype.parallelCollectionScan = deprecate(function(
2156-
this: any,
2157-
options: any,
2158-
callback: Function
2159-
) {
2160-
if (typeof options === 'function') (callback = options), (options = { numCursors: 1 });
2161-
// Set number of cursors to 1
2162-
options.numCursors = options.numCursors || 1;
2163-
options.batchSize = options.batchSize || 1000;
2164-
2165-
options = Object.assign({}, options);
2166-
// Ensure we have the right read preference inheritance
2167-
options.readPreference = ReadPreference.resolve(this, options);
2168-
2169-
if (options.session) {
2170-
options.session = undefined;
2171-
}
2172-
2173-
return executeLegacyOperation(
2174-
this.s.topology,
2175-
parallelCollectionScan,
2176-
[this, options, callback],
2177-
{ skipSessions: true }
2178-
);
2179-
},
2180-
'parallelCollectionScan is deprecated in MongoDB v4.1');
2181-
21822127
/**
21832128
* Run a group command across a collection
21842129
*

src/operations/collection_ops.ts

+1-53
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import ReadPreference = require('../read_preference');
2-
import { Code, Long } from '../bson';
2+
import { Code } from '../bson';
33
import { MongoError } from '../error';
44
import { insertDocuments, updateDocuments } from './common_functions';
55
import {
@@ -285,57 +285,6 @@ function indexInformation(coll: any, options?: object, callback?: Function) {
285285
indexInformationDb(coll.s.db, coll.collectionName, options, callback);
286286
}
287287

288-
/**
289-
* Return N parallel cursors for a collection to allow parallel reading of the entire collection. There are
290-
* no ordering guarantees for returned results.
291-
*
292-
* @function
293-
* @param {Collection} coll Collection instance.
294-
* @param {any} [options] Optional settings. See Collection.prototype.parallelCollectionScan for a list of options.
295-
* @param {Collection~parallelCollectionScanCallback} [callback] The command result callback
296-
*/
297-
function parallelCollectionScan(coll: any, options?: any, callback?: Function) {
298-
// Create command object
299-
const commandObject = {
300-
parallelCollectionScan: coll.collectionName,
301-
numCursors: options.numCursors
302-
};
303-
304-
// Do we have a readConcern specified
305-
decorateWithReadConcern(commandObject, coll, options);
306-
307-
// Store the raw value
308-
const raw = options.raw;
309-
delete options['raw'];
310-
311-
// Execute the command
312-
executeCommand(coll.s.db, commandObject, options, (err?: any, result?: any) => {
313-
if (err) return handleCallback(callback!, err, null);
314-
if (result == null)
315-
return handleCallback(
316-
callback!,
317-
new Error('no result returned for parallelCollectionScan'),
318-
null
319-
);
320-
321-
options = Object.assign({ explicitlyIgnoreSession: true }, options);
322-
323-
const cursors = [];
324-
// Add the raw back to the option
325-
if (raw) options.raw = raw;
326-
// Create command cursors for each item
327-
for (let i = 0; i < result.cursors.length; i++) {
328-
const rawId = result.cursors[i].cursor.id;
329-
// Convert cursorId to Long if needed
330-
const cursorId = typeof rawId === 'number' ? Long.fromNumber(rawId) : rawId;
331-
// Add a command cursor
332-
cursors.push(coll.s.topology.cursor(coll.namespace, cursorId, options));
333-
}
334-
335-
handleCallback(callback!, null, cursors);
336-
});
337-
}
338-
339288
/**
340289
* Save a document.
341290
*
@@ -377,6 +326,5 @@ export {
377326
indexes,
378327
indexExists,
379328
indexInformation,
380-
parallelCollectionScan,
381329
save
382330
};

src/sessions.ts

+1-8
Original file line numberDiff line numberDiff line change
@@ -678,14 +678,7 @@ class ServerSessionPool {
678678
* @param {any} [options]
679679
*/
680680
function commandSupportsReadConcern(command: any, options?: any) {
681-
if (
682-
command.aggregate ||
683-
command.count ||
684-
command.distinct ||
685-
command.find ||
686-
command.parallelCollectionScan ||
687-
command.geoNear
688-
) {
681+
if (command.aggregate || command.count || command.distinct || command.find || command.geoNear) {
689682
return true;
690683
}
691684

test/functional/core/operations.test.js

-72
Original file line numberDiff line numberDiff line change
@@ -349,78 +349,6 @@ describe('Operation tests', function() {
349349
}
350350
});
351351

352-
it('should correctly execute query against cursorId', {
353-
metadata: {
354-
requires: {
355-
mongodb: '>=2.6.0 < 4.1.x',
356-
topology: ['single', 'replicaset']
357-
}
358-
},
359-
360-
test: function(done) {
361-
var self = this;
362-
const config = this.configuration;
363-
const server = config.newTopology();
364-
365-
// Add event listeners
366-
server.on('connect', function(_server) {
367-
// Execute the write
368-
_server.insert(
369-
f('%s.inserts11', self.configuration.db),
370-
[{ a: 1 }, { a: 2 }, { a: 3 }],
371-
{
372-
writeConcern: { w: 1 },
373-
ordered: true
374-
},
375-
function(insertErr, insertResults) {
376-
expect(insertErr).to.be.null;
377-
expect(insertResults.result.n).to.equal(3);
378-
379-
// Execute the command
380-
_server.command(
381-
f('%s.$cmd', self.configuration.db),
382-
{ parallelCollectionScan: 'inserts11', numCursors: 1 },
383-
function(cmdErr, cmdRes) {
384-
expect(cmdErr).to.be.null;
385-
expect(cmdRes).to.not.be.null;
386-
387-
// Create cursor from parallel collection scan cursor id
388-
var cursor = _server.cursor(
389-
f('%s.inserts11', self.configuration.db),
390-
cmdRes.result.cursors[0].cursor.id,
391-
{ documents: cmdRes.result.cursors[0].cursor.firstBatch }
392-
);
393-
394-
// Execute next
395-
cursor._next(function(cursorErr, cursorD) {
396-
expect(cursorErr).to.be.null;
397-
expect(cursorD.a).to.equal(1);
398-
399-
// Execute next
400-
cursor._next(function(secondCursorErr, secondCursorD) {
401-
expect(secondCursorErr).to.be.null;
402-
expect(secondCursorD.a).to.equal(2);
403-
404-
cursor._next(function(thirdCursorErr, thirdCursorD) {
405-
expect(thirdCursorErr).to.be.null;
406-
expect(thirdCursorD.a).to.equal(3);
407-
408-
// Destroy the server connection
409-
_server.destroy(done);
410-
});
411-
});
412-
});
413-
}
414-
);
415-
}
416-
);
417-
});
418-
419-
// Start connection
420-
server.connect();
421-
}
422-
});
423-
424352
it('should correctly kill command cursor', {
425353
metadata: {
426354
requires: {

0 commit comments

Comments
 (0)