[SERVER-9389] Querying 2d indexes with $exists:false fails and the error message is incorrect Created: 18/Apr/13  Updated: 11/Jul/16  Resolved: 12/Nov/13

Status: Closed
Project: Core Server
Component/s: Geo, Querying
Affects Version/s: 2.5.3
Fix Version/s: 2.5.4

Type: Bug Priority: Minor - P4
Reporter: Steve Schlotter Assignee: Unassigned
Resolution: Done Votes: 1
Labels: query_triage
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Mac OSX 10.7.5


Attachments: File server9389.js    
Issue Links:
Duplicate
is duplicated by SERVER-10917 Exists on geospatial fields Closed
Operating System: ALL
Participants:

 Description   

When attempting to find ungeocoded documents I'm getting a misleading error.

db.accounts.find({"locations.coordinates":{"$exists":false}})

returns this error;

"$err" : "geo field only has 1 element :: caused by :: $exists: false",
"code" : 13068

None of my coordinates have only one element.

db.accounts.find({"locations.coordinates":{"$exists":true}})

is successful.



 Comments   
Comment by David Storch [ 12/Nov/13 ]

This affects version 2.5.3, but appears to be fixed in 2.5.4-pre (git hash 3c707bd5a995776d70cc740a0c7220c5986aacde):

> t = db.t
test.t
> t.drop()
false
> t.insert( { locations: [ { coordinates: [1, 1] }, { coordinates: [2, 2] } ] } )
{ "ok" : 1, "n" : 1 }
> t.ensureIndex({'locations.coordinates': '2d'})
> t.find( { "locations.coordinates": { $exists: true } } )
{ "_id" : ObjectId("528282dd26cf58dda5e0228f"), "locations" : [  {  "coordinates" : [  1,  1 ] },  {  "coordinates" : [  2,  2 ] } ] }
> t.find( { "locations.coordinates": { $exists: false } } )
> db.getLastErrorObj()
{ "n" : 0, "connectionId" : 1, "err" : null, "ok" : 1 }

Resolving as fixed and attaching a js regression test.

Comment by Paul Klimashkin [ 05/Aug/13 ]

From version 2.4 this works
db.accounts.find(

{"locations.coordinates": null}

)
But then I don't understand the difference between

{"$exists":false}

and null

Comment by Thyago Schleuss [ 04/Jun/13 ]

I have the same problem. I need to find documents without the location field.

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