[SERVER-14797] mongos does not return matching results after encountering empty documents Created: 05/Aug/14  Updated: 06/Jan/15  Resolved: 12/Aug/14

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

Type: Bug Priority: Critical - P2
Reporter: Thomas Rueckstiess Assignee: Greg Studer
Resolution: Done Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
Tested
Operating System: ALL
Steps To Reproduce:

Start a sharded cluster with 2 shards

mlaunch --sharded 2 --single
 
launching: mongod on port 27018
launching: mongod on port 27019
launching: config server on port 27020
launching: mongos on port 27017
adding shards.

Insert some data, shard the collection on _id

(ve)tr@enter:~/Documents/tickets/CS-14146$ mongo
 
MongoDB shell version: 2.6.3
connecting to: test
mongos> db.getSisterDB('config').settings.update({}, {$set: {value: 1}})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
mongos> for (var i = 0; i < 20000; i++) {
... db.coll.insert({field: i})
... }
WriteResult({ "nInserted" : 1 })
mongos> sh.enableSharding('test')
{ "ok" : 1 }
mongos> sh.shardCollection('test.coll', {_id: 1})
{ "collectionsharded" : "test.coll", "ok" : 1 }
mongos> sh.status()
--- Sharding Status ---
  sharding version: {
    "_id" : 1,
    "version" : 4,
    "minCompatibleVersion" : 4,
    "currentVersion" : 5,
    "clusterId" : ObjectId("53e153e61a06f4155f0e2439")
}
  shards:
    {  "_id" : "shard0000",  "host" : "enter.local:27018" }
    {  "_id" : "shard0001",  "host" : "enter.local:27019" }
  databases:
    {  "_id" : "admin",  "partitioned" : false,  "primary" : "config" }
    {  "_id" : "test",  "partitioned" : true,  "primary" : "shard0000" }
        test.coll
            shard key: { "_id" : 1 }
            chunks:
                shard0000   2
                shard0001   1
            { "_id" : { "$minKey" : 1 } } -->> { "_id" : ObjectId("53e154266632858cc22a2205") } on : shard0000 Timestamp(2, 1)
            { "_id" : ObjectId("53e154266632858cc22a2205") } -->> { "_id" : ObjectId("53e154436632858cc22a530d") } on : shard0000 Timestamp(1, 3)
            { "_id" : ObjectId("53e154436632858cc22a530d") } -->> { "_id" : { "$maxKey" : 1 } } on : shard0001 Timestamp(2, 0)

Run a query that would return an empty document:

mongos> db.coll.find({}, {nonexisting:1, _id:0})
mongos> db.coll.find({}, {nonexisting:1, _id:0}).itcount()
0
mongos> db.coll.find({}, {nonexisting:1, _id:0}).count()
20000
mongos>
bye

On mongod however:

(ve)tr@enter:~/Documents/tickets/CS-14146$ mongo --port 27018
MongoDB shell version: 2.6.3
connecting to: 127.0.0.1:27018/test
> db.coll.find({}, {nonexisting:1, _id:0})
{  }
{  }
{  }
{  }
{  }
{  }
{  }
{  }
{  }
{  }
{  }
{  }
{  }
{  }
{  }
{  }
{  }
{  }
{  }
{  }
Type "it" for more
> db.coll.find({}, {nonexisting:1, _id:0}).count()
12552
> db.coll.find({}, {nonexisting:1, _id:0}).itcount()
12552
>

Participants:

 Description   

mongos and mongod show inconsistent behavior for returning empty documents.

In a sharded collection a find with a projection that results in an empty document is not returned by mongos but just skipped.

mongod on the other hand returns the empty document { }.

See steps to reproduce.



 Comments   
Comment by Githook User [ 12/Aug/14 ]

Author:

{u'username': u'gregstuder', u'name': u'Greg Studer', u'email': u'greg@10gen.com'}

Message: SERVER-14797 simplify parallel.cpp, don't use empty docs as sentinels
Branch: master
https://github.com/mongodb/mongo/commit/c328d06c22c9b693e66dcdf020b3642fb147b8ac

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