Joey Yi Zhao
Joey Yi Zhao

Reputation: 42444

why mongodb find limit doesn't limit any document in the result set

I use below command to find documents in mongodb shell.

> db.companies.find().limit(1).count()
18801

you can see the output is 18801 which means the limit(1) function doesn't have any impact on the command. Did I miss anything wrong?

Upvotes: 0

Views: 68

Answers (1)

JohnnyHK
JohnnyHK

Reputation: 311855

count accepts an optional applySkipLimit parameter for this purpose. So use count(true) if you want its result to consider the effects of skip and limit:

> db.companies.find().limit(1).count(true)
1

Upvotes: 1

Related Questions