query spring mongo limit or skip test

query spring mongo
query.skip(-1L).limit(2) same as skip(0).limit(2)
query.skip(0L).limit(-2) block, seems equals no limit

query.skip(0L).limit(0) block, seems equals no limit

aggregation will error when skip or limit is negative

--------------------------------------------------------------------------------------------------

query mongo
db.getCollection('xxx').find({}).skip(0).limit(-2) same as skip(0).limit(2)

find will error when skip is negative

aggregation will error when skip or limit is negative

 

https://docs.mongodb.com/manual/reference/method/cursor.limit/index.html

Zero Value

limit() value of 0 (i.e. .limit(0)) is equivalent to setting no limit.

Negative Values

A negative limit is similar to a positive limit but closes the cursor after returning a single batch of results. 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 specified limit. By passing a negative limit, the client indicates to the server that it will not ask for a subsequent batch via getMore.

posted @ 2020-09-22 10:18  tonggc1668  阅读(295)  评论(0编辑  收藏  举报