[SERVER-25128] $collStats and $indexStats cannot be used on a view with a non-empty pipeline Created: 18/Jul/16  Updated: 06/Dec/22  Resolved: 13/Dec/16

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

Type: Bug Priority: Major - P3
Reporter: Kevin Albertson Assignee: Backlog - Query Team (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to SERVER-24568 Reflect operations on views in their ... Closed
Assigned Teams:
Query
Operating System: ALL
Steps To Reproduce:

db.runCommand({create: "view", viewOn: "coll", pipeline: [{$match: {}}]});
db.view.aggregate([{$collStats: {latencyStats: {}}}]);
// Alternatively db.view.latencyStats();

Will produce this error:

2016-07-18T13:40:18.285-0400 E QUERY    [thread1] Error: command failed: {
	"ok" : 0,
	"errmsg" : "$collStats is only valid as the first stage in a pipeline.",
	"code" : 2
} : aggregate failed :

Participants:

 Description   

The $collStats aggregation stage, which will contain relevant statistics about operations run on views, cannot be run on a view if the pipeline is non-empty since it must be the first stage. This also applies to the $indexStats stage, though it's less clear whether we would want $indexStats to run on a view.



 Comments   
Comment by Ian Whalen (Inactive) [ 13/Dec/16 ]

Gone Away since a special case has been added for $collStats on a view in the pipeline command, and there is no need to fix this for $indexStats.

Comment by Kevin Albertson [ 19/Jul/16 ]

While it is easy to simply check for $collStats/$indexStats as the first stage and exclude the view pipeline in that case, this might set an undesired precedent. For example, suppose a view with only $indexStats is made as follows:

db.runCommand({create: "view", viewOn: "coll", pipeline: [{$indexStats: {}}]});

I would think the intention is to only allow access to $indexStats through this view, and to disallow $collStats. If we later add additional meta stages like $collStats/$indexStats, it is not clear to me how they would be handled.

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