- Reference >
mongoShell Methods >- Cursor Methods >
- cursor.maxScan()
cursor.maxScan()¶
On this page
Definition¶
-
cursor.maxScan()¶ New in version 3.2.
Specifies a maximum number of documents or index keys the query plan will scan. Once the limit is reached, the query terminates execution and returns the current batch of results.
maxScan()has the following syntax:The method
cursor.maxScanhas the following parameter:Parameter Type Description maxScanint, long, or double The maximum number of documents or index keys that the query plan will scan. Returns: The cursor that maxScan()is attached to with a modified result set based on themaxScanparameter. This allows for additional cursor modifiers to be chained.
Behavior¶
For collection scans, maxScan is the maximum number of documents scanned
before the query results are returned. For index scans, maxScan is the
maximum number of index keys examined.
Using a value of 0 is equivalent to not using cursor.maxScan().
Example¶
Given the following data:
Assuming this query were answered with a collection scan,
the following limits the number of documents to scan to 5:
The operation returns:
If this query were answered using an index scan on { status : 1 }, the
same operation returns the following: