OPTIONS
翻译或纠错本页面

cursor.limit()

Definition

cursor.limit()

Use the limit() method on a cursor to specify the maximum number of documents the cursor will return. limit() is analogous to the LIMIT statement in a SQL database.

注解

You must apply limit() to the cursor before retrieving any documents from the database.

Use limit() to maximize performance and prevent MongoDB from returning more results than required for processing.

Behavior

Supported Values

The behavior of limit() is undefined for values less than -231 and greater than 231.

Negative Values

A limit() value of 0 (i.e. .limit(0)) is equivalent to setting no limit. A negative limit is similar to a positive limit, but a negative limit prevents the creation of a cursor such that only a single batch of results is returned. As such, with a negative limit, if the limited result set does not fit into a single batch, the number of documents received will be less than the limit.