[SERVER-2322] $exists requires true, should also accept 1 Created: 03/Jan/11  Updated: 12/Jul/16  Resolved: 06/Apr/11

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

Type: Bug Priority: Minor - P4
Reporter: Roy Smith Assignee: Aaron Staple
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by SERVER-2093 $exists : X Closed
Operating System: ALL
Participants:

 Description   

I would have expected the following two queries to be identical. Apparently, $exists requires an explicit "true". By analogy with the usual query syntax, I would have expected $exits: 1 to be the same as $exists: true, but it appears not to be. I'm not sure if this is a bug, but it certainly does violate the principle of least astonishment.

> db.users.find({is_dup_of: {$exists: true}}).count()
225
> db.users.find({is_dup_of: {$exists: 1}}).count()
304849



 Comments   
Comment by Githook User [ 26/Mar/14 ]

Author:

{u'username': u'RedBeard0531', u'name': u'Mathias Stearn', u'email': u'mathias@10gen.com'}

Message: SERVER-2322 use correct collection name in test

(cherry picked from commit 5205b62d5c0517a152ce739ab11ec0b3a9cd1859)
Branch: v2.6
https://github.com/mongodb/mongo/commit/b90627fb9894108e94eec133bd7dfb3073d7f7ae

Comment by Githook User [ 26/Mar/14 ]

Author:

{u'username': u'RedBeard0531', u'name': u'Mathias Stearn', u'email': u'mathias@10gen.com'}

Message: SERVER-2322 use correct collection name in test
Branch: master
https://github.com/mongodb/mongo/commit/5205b62d5c0517a152ce739ab11ec0b3a9cd1859

Comment by auto [ 31/Aug/11 ]

Author:

{u'login': u'stbrody', u'name': u'Spencer T Brody', u'email': u'spencer@10gen.com'}

Message: Extend tests for $exists accepting 1 and 0 so that the tests can catch SERVER-2322.
Branch: master
https://github.com/mongodb/mongo/commit/7f9fa28a4d008582ac63ba31c9f15cdb55913fb3

Comment by Chris [ 30/Aug/11 ]

+1 this is definitely a DANGEROUS violation of the principle of least astonishment IMHO, and should be fixed! If you use $exists with a .remove() operation, you could end up deleting /everything in your collection except what you are naively trying to remove/ OUCH!

Comment by auto [ 05/Apr/11 ]

Author:

{u'login': u'astaple', u'name': u'Aaron', u'email': u'aaron@10gen.com'}

Message: SERVER-2322 Allow specification of non boolean value with exists operator
Branch: master
https://github.com/mongodb/mongo/commit/3a5326d9b4a54f6df5d4307f4fc73bcc94212d43

Generated at Thu Feb 08 02:59:37 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.