Details
Description
I tried query to sharded collection with limit() method at mongo shell, and sometimes got less documents than it should.
Test code (attached below):
|
test.js |
db = connect("localhost:27017/myTest"); |
|
|
print( "Prepareing test data" ); |
db.adminCommand( {enablesharding: "myTest"}); |
db.myColl.drop();
|
db.adminCommand( {shardcollection: "myTest.myColl", key: {key:1}} ); |
var padding = ''; for (var i=0; i<10000; i++){ padding += '*'; } |
for (var i=0; i<5000; i++){ db.myColl.save({key: 0, value: i, padding: padding}); } |
|
|
var conf = db.getSisterDB("config"); |
print( "Number of the shards : " + conf.shards.count() ); |
print( "Chunks : " ); |
conf.chunks.find({ns:"myTest.myColl"}).forEach(printjson); |
print( "Test result:" ); |
|
|
for(var lm=100; lm<2000; lm+=100){ |
var i=0;db.myColl.find().limit(lm).forEach(function(x){i=i+1}); |
print(lm + ":" + i + (lm == i ? "" : " <- !?")) |
}
|
and result :
$ mongo --nodb test.js
|
MongoDB shell version: 2.0.2
|
connecting to: localhost:27017/myTest
|
Prepareing test data
|
Number of the shards : 3
|
Chunks :
|
"_id" : "myTest.myColl-key_MinKey",
|
"lastmod" : {
|
"t" : 1000,
|
"i" : 0
|
},
|
"ns" : "myTest.myColl",
|
"min" : {
|
"key" : { $minKey : 1 }
|
},
|
"max" : {
|
"key" : { $maxKey : 1 }
|
},
|
"shard" : "shard1"
|
}
|
Test result:
|
100:100
|
200:115 <- !?
|
300:300
|
400:400
|
500:500
|
600:600
|
700:554 <- !?
|
800:454 <- !?
|
900:900
|
1000:1000
|
1100:1100
|
1200:993 <- !?
|
1300:893 <- !?
|
1400:793 <- !?
|
1500:1500
|
1600:1600
|
1700:1700
|
1800:1332 <- !?
|
1900:1232 <- !?
|
I tried same test via mondod(shard) directly and it's OK.
I tried same test in single not sharded collection and it's OK.
I tried same test with Perl driver (MongoDB 0.45 CPAN module) and it's OK. (test code and result attached)