[SERVER-5355] negative count limit brackets result to 0 Created: 22/Mar/12  Updated: 11/Jul/16  Resolved: 27/Apr/12

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: None
Fix Version/s: 2.1.1

Type: Bug Priority: Major - P3
Reporter: Aaron Staple Assignee: Randolph Tan
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File wrongcountlimit.patch    
Issue Links:
Related
is related to SERVER-5151 sharded count can return a negative v... Closed
Operating System: ALL
Participants:

 Description   

If a negative limit is provided to find, results are capped to the negation of that limit. If a negative limit is provided to count, 0 is returned.

> c.save( {} )
> c.save( {} )
> c.save( {} )
> c.find().limit( -2 ).count( true )
0
> c.find().limit( -2 ).itcount()
2



 Comments   
Comment by auto [ 27/Apr/12 ]

Author:

{u'login': u'', u'name': u'Randolph Tan', u'email': u'randolph@10gen.com'}

Message: SERVER-5355 negative count limit brackets result to 0

Applied patch from Peter Grant, added test for mongos and fixed limit 0 count.
Branch: master
https://github.com/mongodb/mongo/commit/557f0c1433f131fc68bfefbdf85bf54df4470788

Comment by Peter Grant [ 26/Apr/12 ]

Attached patch to correct negative limit causing wrong count.

Comment by Peter Grant [ 24/Apr/12 ]

If a query and a negative limit are provided to count, limit is ignored.

> c.save({name: "apple"});
> c.save({name: "apple"});
> c.save({name: "apple"});
> c.find().limit(-2).count(true)
0
> c.find({name: "apple"}).limit(-2).count(true)
3

Generated at Thu Feb 08 03:08:38 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.