Using one mongo shell, start up a sharded environment with two shards as follows:
C:\mongodb\mongodb-win32-x86_64-1.8.2\bin>mongo --nodb
MongoDB shell version: 1.8.2
> var st = new ShardingTest(name = "sharded", shards = 2, mongoses = 1)
...
> st.s
connection to 127.0.0.1:31000
Now using another mongo shell, attach to the mongos on port 31000 and run this test:
C:\mongodb\mongodb-win32-x86_64-1.8.2\bin>mongo --port 31000
MongoDB shell version: 1.8.2
connecting to: 127.0.0.1:31000/test
> use admin
switched to db admin
> db.runCommand(
)
{ "ok" : 1 }> db.runCommand({shardcollection:"test.test", key:{_id:1}})
{ "collectionsharded" : "test.test", "ok" : 1 }> use test
switched to db test
> db.test.insert({_id:1})
> db.test.insert({_id:2})
> db.test.insert({_id:3})
> db.test.insert({_id:4})
> db.test.insert({_id:5})
> db.test.insert({_id:6})
> db.test.find()
> db.test.find().skip(4).limit(2)
{ "_id" : 5 } { "_id" : 6 }> db.test.find().skip(4).limit(-2)
>
The last find with a negative limit of -2 should have returned two documents also.