[SERVER-13788] $exists in find() gives error Created: 30/Apr/14  Updated: 10/Dec/14  Resolved: 30/Apr/14

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

Type: Bug Priority: Critical - P2
Reporter: Xiong Sheng [X] Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Participants:

 Description   

The following query can be executed successfully:

mydb> db.testData.find({"y":{"$exists" : true}}, {"y" : null})

But, swith the places of the criteria:

mydb> db.testData.find({"y" : null},{"y":{"$exists" : true}})

system gives the following error:

error: {
        "$err" : "Can't canonicalize query: BadValue Unsupported projection opti
on: y: { $exists: true }",
        "code" : 17287
}



 Comments   
Comment by Alvin Richards (Inactive) [ 30/Apr/14 ]

The reference for the find command can be found here

http://docs.mongodb.org/manual/reference/method/db.collection.find/

Essentially you have added a projection criteria as the second parameter (like the items in the "select" statement in SQL).

  • Example 1: {"y" : null}
  • Example 2: {"y":{"$exists" : true}}

The second is not a valid projection operator, see here for details of what you can do http://docs.mongodb.org/manual/reference/operator/projection/.

You may be trying to do a logical $and or $or between the $exists and null comparison, see here for details http://docs.mongodb.org/manual/reference/operator/query/#logical

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