[SERVER-9126] Cannot get query plan or status for distinct() routed through mongos Created: 25/Mar/13  Updated: 05/Aug/15  Resolved: 05/Aug/15

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 2.2.3, 2.4.1
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Jay Wineinger Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-15020 Implement explain for the distinct co... Closed
Related
related to SERVER-10448 Revamp explain() formatting Closed
Operating System: ALL
Steps To Reproduce:

Issue a distinct command using runCommand. Observe the output does not have a query plan nor status.

Participants:

 Description   

I am unable to find any way to get the query plan and stats for a distinct query in mongo shell. explain() is not valid to chain onto distinct(). The 2.2 documentation says (http://docs.mongodb.org/v2.2/reference/command/distinct/) says that "the command returns a document that contains an array of the distinct values as well as the query plan and status."

mongos> db.actions.distinct("a",

{...}).explain()
Mon Mar 25 14:24:35 TypeError: db.actions.distinct("a", {...}

).explain is not a function (shell):1

mongos> db.runCommand({distinct:'actions', key:"a", query:{...}})

{ "values" : [ "love" ], "ok" : 1 }

 Comments   
Comment by Qingyang Chen [ 05/Aug/15 ]

Closing as duplicate of SERVER-15020.

You can now do db.<collection>.explain(...).distinct(...). An example of the output:

{
	"queryPlanner" : {
		"mongosPlannerVersion" : 1,
		"winningPlan" : {
			"stage" : "SINGLE_SHARD",
			"shards" : [
				{
					"shardName" : "shard0000",
					"connectionString" : "Qingyangs-MacBook-Pro.local:30000",
					"serverInfo" : {
						"host" : "Qingyangs-MacBook-Pro.local",
						"port" : 30000,
						"version" : "3.1.7-pre-",
						"gitVersion" : "197ea2a625dc04d95a7ad4933283b5f02ca2ad9e"
					},
					"plannerVersion" : 1,
					"namespace" : "test.foo",
					"indexFilterSet" : false,
					"parsedQuery" : {
						"$and" : [ ]
					},
					"winningPlan" : {
						"stage" : "PROJECTION",
						"transformBy" : {
							"_id" : 1
						},
						"inputStage" : {
							"stage" : "DISTINCT_SCAN"
						}
					},
					"rejectedPlans" : [ ]
				}
			]
		}
	},
	"ok" : 1
}

Comment by Thomas Rueckstiess [ 26/Mar/13 ]

I can confirm that the distinct command will only return the "stats" field, when the collection is not sharded.

Before sharding the collection:

mongos> db.runCommand({distinct: "actions", key:"a"})
{
	"values" : [
		"love"
	],
	"stats" : {
		"n" : 1,
		"nscanned" : 1,
		"nscannedObjects" : 0,
		"timems" : 0,
		"cursor" : "BtreeCursor a_1"
	},
	"ok" : 1
}

After sharding the collection:

mongos> sh.enableSharding("test")
mongos> sh.shardCollection("test.actions", {_id: 1})
 
mongos> db.runCommand({distinct: "actions", key:"a"})
{ "values" : [ "love" ], "ok" : 1 }

Need to confirm if this is by choice (or due to certain implementation limitations) or if this is a bug.

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