[SERVER-14091] $query unsupported operator Created: 29/May/14  Updated: 19/Jun/15  Resolved: 26/Jun/14

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

Type: Bug Priority: Major - P3
Reporter: Steve Owens Assignee: Thomas Rueckstiess
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-6767 Interpret $query as special so you ca... Closed
Operating System: ALL
Participants:

 Description   

According to the latest docs the following should be supported:

When I run the following query I get results:

db.mycollection.find({"$query":{}, "$orderby":{"myfield":1});

When I run the following explain:

db.mycollection.find({"$query":{}, "$orderby":{"myfield":1}).explain();

I get the following error:

2014-05-29T15:29:46.939-0700 error: {
	"$err" : "Can't canonicalize query: BadValue unknown top level operator: $query",
	"code" : 17287
} at src/mongo/shell/query.js:131

Why can't I do an explain on a valid query?



 Comments   
Comment by Ramon Fernandez Marina [ 19/Jun/15 ]

Thanks for the additional information LEisenstein. This is expected, as SERVER-6767 has not been resolved yet. Feel free to watch SERVER-6767 for updates.

Regards,
Ramón.

Comment by Larry Eisenstein [X] [ 19/Jun/15 ]

Late comment, but I have run into the same issue on Mongo 3.0.3.

This query comes from the log console. I was reviewing the logged queries and trying to run .explain() to see what it was doing.

Comment by Thomas Rueckstiess [ 29/May/14 ]

Hi Steve,

This is a known issue and described in SERVER-6767. Currently, the find syntax with {"$query": ... "$orderby": ...} does not support an added explain via method chaining, i.e. with .explain().

As a workaround, you can use either of these alternatives:

db.mycollection.find().sort({myfield: 1}).explain()
db.mycollection.find({ "$query": {}, "$orderby": { myfield: 1 }, "$explain": true })

You mention that this should be supported "According to the latest docs". Is there a usage example in our documentation that says this works? Can you point me to the docs page please?

Regards,
Thomas

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