[SERVER-61274] $collStats for view on sharded collection only returns stats for primary shard Created: 05/Nov/21  Updated: 06/Dec/22

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

Type: Bug Priority: Major - P3
Reporter: James Wahlin Assignee: Backlog - Query Optimization
Resolution: Unresolved Votes: 0
Labels: read-only-views
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Query Optimization
Operating System: ALL
Steps To Reproduce:

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>

Participants:

 Description   

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.


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