Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-61274

$collStats for view on sharded collection only returns stats for primary shard

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:
    • Query Optimization
    • ALL
    • Hide
      mongos> sh.enableSharding("test");
      {
      	"ok" : 1,
      	"$clusterTime" : {
      		"clusterTime" : Timestamp(1636120119, 2),
      		"signature" : {
      			"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
      			"keyId" : NumberLong(0)
      		}
      	},
      	"operationTime" : Timestamp(1636120119, 1)
      }
      mongos> sh.shardCollection("test.test", {_id: "hashed"});
      {
      	"collectionsharded" : "test.test",
      	"ok" : 1,
      	"$clusterTime" : {
      		"clusterTime" : Timestamp(1636120139, 33),
      		"signature" : {
      			"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
      			"keyId" : NumberLong(0)
      		}
      	},
      	"operationTime" : Timestamp(1636120139, 27)
      }
      mongos> for (var j = 0 ; j < 100; ++j) {db.test.insert({x: j});}
      WriteResult({ "nInserted" : 1 })
      mongos> db.createView("view", "test", [{$addFields: {y: 1}}]);
      {
      	"ok" : 1,
      	"$clusterTime" : {
      		"clusterTime" : Timestamp(1636120216, 2),
      		"signature" : {
      			"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
      			"keyId" : NumberLong(0)
      		}
      	},
      	"operationTime" : Timestamp(1636120216, 2)
      }
      mongos> db.test.aggregate({$collStats: {}});
      { "ns" : "test.test", "shard" : "__unknown_name__-rs0", "host" : "james:20000", "localTime" : ISODate("2021-11-05T13:50:34.925Z") }
      { "ns" : "test.test", "shard" : "__unknown_name__-rs1", "host" : "james:20001", "localTime" : ISODate("2021-11-05T13:50:34.925Z") }
      mongos> db.view.aggregate({$collStats: {}});
      { "ns" : "test.view", "shard" : "__unknown_name__-rs1", "host" : "james:20001", "localTime" : ISODate("2021-11-05T13:50:41.308Z") }
      mongos>
      
      Show
      mongos> sh.enableSharding( "test" ); { "ok" : 1, "$clusterTime" : { "clusterTime" : Timestamp(1636120119, 2), "signature" : { "hash" : BinData(0, "AAAAAAAAAAAAAAAAAAAAAAAAAAA=" ), "keyId" : NumberLong(0) } }, "operationTime" : Timestamp(1636120119, 1) } mongos> sh.shardCollection( "test.test" , {_id: "hashed" }); { "collectionsharded" : "test.test" , "ok" : 1, "$clusterTime" : { "clusterTime" : Timestamp(1636120139, 33), "signature" : { "hash" : BinData(0, "AAAAAAAAAAAAAAAAAAAAAAAAAAA=" ), "keyId" : NumberLong(0) } }, "operationTime" : Timestamp(1636120139, 27) } mongos> for ( var j = 0 ; j < 100; ++j) {db.test.insert({x: j});} WriteResult({ "nInserted" : 1 }) mongos> db.createView( "view" , "test" , [{$addFields: {y: 1}}]); { "ok" : 1, "$clusterTime" : { "clusterTime" : Timestamp(1636120216, 2), "signature" : { "hash" : BinData(0, "AAAAAAAAAAAAAAAAAAAAAAAAAAA=" ), "keyId" : NumberLong(0) } }, "operationTime" : Timestamp(1636120216, 2) } mongos> db.test.aggregate({$collStats: {}}); { "ns" : "test.test" , "shard" : "__unknown_name__-rs0" , "host" : "james:20000" , "localTime" : ISODate( "2021-11-05T13:50:34.925Z" ) } { "ns" : "test.test" , "shard" : "__unknown_name__-rs1" , "host" : "james:20001" , "localTime" : ISODate( "2021-11-05T13:50:34.925Z" ) } mongos> db.view.aggregate({$collStats: {}}); { "ns" : "test.view" , "shard" : "__unknown_name__-rs1" , "host" : "james:20001" , "localTime" : ISODate( "2021-11-05T13:50:41.308Z" ) } mongos>

      An aggregation pipeline with a $collStats stage against a sharded collection will return information for every shard. If the same pipeline is executed against a view on that collection stats are only returned for the primary shard. Behavior should be consistent between the 2.

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            james.wahlin@mongodb.com James Wahlin
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: