[SERVER-6767] Interpret $query as special so you can copy profiler/logged queries into shell Created: 14/Aug/12  Updated: 20/Jun/16  Resolved: 19/Oct/15

Status: Closed
Project: Core Server
Component/s: Shell, Usability
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Minor - P4
Reporter: Scott Hernandez (Inactive) Assignee: David Storch
Resolution: Won't Fix Votes: 0
Labels: neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by SERVER-8447 $query with count and $hint not behav... Closed
is duplicated by SERVER-10079 Cannot use $query together with $comment Closed
is duplicated by SERVER-10352 doing explain on $query on the shell ... Closed
is duplicated by SERVER-14091 $query unsupported operator Closed
is duplicated by SERVER-14564 explain() doesn't work with $min / $max Closed
is duplicated by SERVER-17004 shell should raise a useful error on ... Closed
is duplicated by SERVER-17928 choosing query field in system.profile Closed
is duplicated by SERVER-24341 Find on admin.$cmd.sys.inprog asserts... Closed
Related
related to SERVER-8025 shell supports "query" works as a met... Closed
related to SERVER-9812 User query is interpreted incorrectly... Closed
related to SERVER-17171 the query for collection with "query"... Closed
related to SERVER-6768 MongoDB Profiler creates illegal docu... Closed
is related to DOCS-856 Create page explaining log/profile fo... Closed
Backwards Compatibility: Fully Compatible
Participants:

 Description   

If the query starts with [$]query (like db.coll.find({$query:{...}})) then we should set the _special boolean to true. This will allow running this:

db.coll.find({$query:...}).explain()



 Comments   
Comment by David Storch [ 19/Oct/15 ]

Hi drsmith,

I believe the shell command you are looking for in order to explain a query with a min and with a limit is as follows:

db.coll.find({...}).min({...}).limit(X).explain();

Granted, the docs about how to use explain are a bit scattered and hard to track down, so I've filed an improvement request with our documentation team: DOCS-6403.

Note that starting in version 3.2, use of $-prefixed options inside the query predicate ($min, $max, $maxScan, $returnKey, etc.) will be deprecated. Instead, shell code should use the corresponding shell helpers (.min(), .max(), .maxScan(), .returnKey() etc.). This will be documented by DOCS-5986. The reasoning behind this is that for 3.2 we added new commands for issuing queries under SERVER-15176 which accept the query parameters in a different format. Use of the shell helpers like .min() abstracts over the underlying network protocol and allows the shell to pass the parameters using the proper format.

Since the $query format is now illegal in the shell, I am closing this ticket as "Won't Fix".

Best,
Dave

Comment by Devin Smith [ 19/Oct/15 ]

Almost 3 years! Would be great to get this fixed.

I've got a query I don't think I can use the workaround (suggested here https://jira.mongodb.org/browse/SERVER-14564) for.

db.collection.find({$min:{...}}, {$query:{}}).limit(X).explain()

is not the same as

db.collection.find({$min:{...}}, {$query:{}}, $explain: true).limit(X).

Is there a workaround to limit before the explain?

Unless there is a way to

Comment by Greg Studer [ 27/Dec/12 ]

Reverted pending further discussion.

Comment by auto [ 27/Dec/12 ]

Author:

{u'date': u'2012-12-27T18:01:34Z', u'email': u'greg@10gen.com', u'name': u'Greg Studer'}

Message: Revert "SERVER-6767: do smarter things with find({$query:...}).explain()"

This reverts commit d06c2ff635acc548e73381d669d9f66f7e225ea8.
Branch: master
https://github.com/mongodb/mongo/commit/2b6c0b2de87857f007adee67bb06c81b414c41fc

Comment by auto [ 26/Dec/12 ]

Author:

{u'date': u'2012-12-26T23:36:02Z', u'email': u'scotthernandez@gmail.com', u'name': u'Scott Hernandez'}

Message: SERVER-6767: do smarter things with find({$query:...}).explain()
Branch: master
https://github.com/mongodb/mongo/commit/d06c2ff635acc548e73381d669d9f66f7e225ea8

Comment by Scott Hernandez (Inactive) [ 05/Dec/12 ]

Currently this creates a query which wraps the $query and will cause a collection scan.

It basically becomes this query:

{query:{ $query : ... }, $explain: true}

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