Navigation
This version of the documentation is archived and no longer supported.

parallelCollectionScan

On this page

parallelCollectionScan

New in version 2.6.

Allows applications to use multiple parallel cursors when reading all the documents from a collection, thereby increasing throughput. The parallelCollectionScan command returns a document that contains an array of cursor information.

Each cursor provides access to the return of a partial set of documents from a collection. Iterating each cursor returns every document in the collection. Cursors do not contain the results of the database command. The result of the database command identifies the cursors, but does not contain or constitute the cursors.

Important

  • The server may return fewer cursors than requested.
  • This command will not return more than one cursor for the WiredTiger storage engine.

The command has the following syntax:

{
  parallelCollectionScan: "<collection>",
  numCursors: <integer>,
  readConcern: <document>,
  maxTimeMS: <integer>
}

The parallelCollectionScan command takes the following fields:

Field Type Description
parallelCollectionScan string The name of the collection.
numCursors integer The maximum number of cursors to return. Must be between 1 and 10000, inclusive.
readConcern document

Optional. Specifies the read concern.

The readConcern option has the following syntax:

Changed in version 3.6.

readConcern: { level: <value> }

Possible read concern levels are:

For more formation on the read concern levels, see Read Concern Levels.

For "local" (default) or "majority" read concern level, you can specify the afterClusterTime option to have the read operation return data that meets the level requirement and the specified after cluster time requirement. For more information, see Read Operations and Causally Consistent Sessions.

maxTimeMS non-negative integer

Optional. Specifies a time limit in milliseconds for processing operations on a cursor. If you do not specify a value for maxTimeMS, operations will not time out. A value of 0 explicitly specifies the default unbounded behavior.

MongoDB terminates operations that exceed their allotted time limit using the same mechanism as db.killOp(). MongoDB only terminates an operation at one of its designated interrupt points.

parallelCollectionScan is only available for mongod, and it cannot operate on a sharded cluster.

Example

Override Default Read Concern

To override the default read concern level of "local", use the readConcern option.

The following operation on a replica set specifies a Read Concern of "majority" to read the most recent copy of the data confirmed as having been written to a majority of the nodes.

Note

db.runCommand(
   {
      parallelCollectionScan: "restaurants",
      numCursors: 5,
      readConcern: { level: "majority" }
   }
)

To ensure that a single thread can read its own writes, use "majority" read concern and "majority" write concern against the primary of the replica set.

Output

The parallelCollectionScan command returns a document containing the array of cursor information:

{
    "cursors" : [
        {
            "cursor" : {
                "firstBatch" : [ ],
                "ns" : "<database name>.<collection name>",
                "id" : NumberLong("155949257847")
            },
            "ok" : true
        }
    ],
    "ok" : 1
}
parallelCollectionScan.cursors

An array with one or more cursors returned with the command.

parallelCollectionScan.cursors.cursor

For each cursor returned, a document with details about the cursor.

parallelCollectionScan.cursors.cursor.firstBatch

An empty first batch is useful for quickly returning a cursor or failure message without doing significant server-side work. See cursor batches.

parallelCollectionScan.cursors.cursor.ns

The namespace for each cursor.

parallelCollectionScan.cursors.cursor.id

The unique id for each cursor.

parallelCollectionScan.cursors.ok

The status of each cursor returned with the command.

parallelCollectionScan.ok

A value of 1 indicates the parallelCollectionScan command succeeded. A value of 0 indicates an error.

←   insert resetError  →