[SERVER-2135] distinct() broken for indexed geo fields Created: 22/Nov/10  Updated: 12/Jul/16  Resolved: 06/Apr/11

Status: Closed
Project: Core Server
Component/s: Geo, Index Maintenance
Affects Version/s: 1.7.3
Fix Version/s: 1.9.0

Type: Bug Priority: Major - P3
Reporter: Brandon Heller Assignee: Greg Studer
Resolution: Done Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

OS X 64-bit, 1.7.3 prebuilt


Attachments: File geo_distinct.js    
Operating System: ALL
Participants:

 Description   

w/1.7.3, distinct() doesn't seem to work with an indexed geo field, though in it does in 1.6.4.

To replicate, run these 3 lines in mongo:

use test_distinct
db.commits.save(

{ "_id" : ObjectId("4ce63ec2f360622431000013"), "loc" : [ 55.59664, 13.00156 ], "author" : "FredrikL"}

)
db.runCommand(

{distinct: 'commits', key: 'loc'}

)

OK, we see one commit. But if the geo field is indexed, we get an exception.

> db.commits.ensureIndex(

{'loc': '2d'}

)
> db.commits.getIndexes()
[
{
"name" : "id",
"ns" : "test_distinct.commits",
"key" :

{ "_id" : 1 }

,
"v" : 0
},
{
"_id" : ObjectId("4ceadeb04ca1623d1ab8bcf3"),
"ns" : "test_distinct.commits",
"key" :

{ "loc" : "2d" }

,
"name" : "loc_"
}
]
> db.runCommand(

{distinct: 'commits', key: 'loc'}

)
{
"errmsg" : "exception: best guess plan requested, but scan and order required: query: {} order:

{ loc: \"2d\" }

choices:

{ $natural: 1 }

",
"code" : 13284,
"ok" : 0
}

In 1.6.4, this works (same inputs as above)

> db.runCommand(

{distinct: 'commits', key: 'loc'}

)

{ "values" : [ 13.00156, 55.59664 ], "ok" : 1 }

 Comments   
Comment by auto [ 06/Apr/11 ]

Author:

{u'login': u'gregstuder', u'name': u'gregs', u'email': u'greg@10gen.com'}

Message: skip indices which require sorting for distinct SERVER-2135
Branch: master
https://github.com/mongodb/mongo/commit/a3b7bb6b8339433b7926477307f0c3c185beb48f

Comment by Greg Studer [ 06/Apr/11 ]

Test case to reproduce.

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