[SERVER-36368] db.XXX.find returns no documents but db.XXX.count return document rows under mongodb sharding Created: 31/Jul/18  Updated: 27/Oct/23  Resolved: 31/Jul/18

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

Type: Bug Priority: Major - P3
Reporter: Jianfeng Xu Assignee: Nick Brewer
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Participants:

 Description   

In mongodb version v3.4.12, db.XXX.find returns no documents but db.XXX.count return document count under mongodb sharding. Any idea! Thanks!

mongos> db['live-hls'].find({fileType:"0","$or":[{"isDelete":{"$exists":false}},{"isDelete":false}],expireDate:{$gt:0,$lt:1532361663004}}) 
mongos> db['live-hls'].count({fileType:"0","$or":[{"isDelete":{"$exists":false}},{"isDelete":false}],expireDate:{$gt:0,$lt:1532361663004}}) 
1077 
mongos> db['live-hls'].find({fileType:"0","$or":[{"isDelete":{"$exists":false}},{"isDelete":false}],expireDate:{$gt:0,$lt:1532361663004}})
mongos> db['live-hls'].find({fileType:"0","$or":[{"isDelete":{"$exists":false}},{"isDelete":false}],expireDate:{$gt:0,$lt:1532361663004}}).count()
1077
mongos> db['live-hls'].find({fileType:"0",expireDate:{$gt:0,$lt:1532361663004}}).count()
1077
mongos> db['live-hls'].find({fileType:"0",expireDate:{$lt:1532361663004}}).count()
1077

mongos> sh.status()
--- Sharding Status --- 
  sharding version: {
        "_id" : 1,
        "minCompatibleVersion" : 5,
        "currentVersion" : 6,
        "clusterId" : ObjectId("587f6bc3d995eccd9ab9b1ac")
  }
  shards:
        {  "_id" : "shard1",  "host" : "shard1/10.23.135.140:17089,10.23.135.141:17089,10.23.135.142:17089",  "state" : 1 }
        {  "_id" : "shard2",  "host" : "shard2/10.23.135.140:17090,10.23.135.141:17090,10.23.135.142:17090",  "state" : 1 }
        {  "_id" : "shard3",  "host" : "shard3/10.23.135.140:17091,10.23.135.141:17091,10.23.135.142:17091",  "state" : 1 }
        {  "_id" : "shard4",  "host" : "shard4/10.23.135.140:17092,10.23.135.141:17092,10.23.135.142:17092",  "state" : 1 }
        {  "_id" : "shard5",  "host" : "shard5/10.23.135.140:17093,10.23.135.141:17093,10.23.135.142:17093",  "state" : 1 }
        {  "_id" : "shard6",  "host" : "shard6/10.23.135.140:17094,10.23.135.141:17094,10.23.135.142:17094",  "state" : 1 }
        {  "_id" : "shard7",  "host" : "shard7/10.23.135.140:17095,10.23.135.141:17095,10.23.135.142:17095",  "state" : 1 }
  active mongoses:
        "3.4.12" : 4
  autosplit:
        Currently enabled: yes
  balancer:
        Currently enabled:  yes
        Currently running:  no
NaN
                Balancer active window is set between 6:00 and 18:00 server local time
        Failed balancer rounds in last 5 attempts:  0
        Migration Results for the last 24 hours: 
                No recent migrations
  databases:



 Comments   
Comment by Nick Brewer [ 31/Jul/18 ]

popgo As the 3.4 documentation notes, count can be inaccurate on sharded clusters. This has been addressed in version 4.0 so that counts with a query predicate (such as yours) will report accurately. That said, aggregation is the recommended method for performing counts on sharded clusters.

For MongoDB-related support discussion please post on the mongodb-user group or Stack Overflow with the mongodb tag.

-Nick

Generated at Thu Feb 08 04:42:53 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.