Geo Query

33 views
Skip to first unread message

Ayman Natsheh

unread,
Nov 14, 2011, 2:49:54 AM11/14/11
to mongodb-user
Hi,

I'm facing a problem querying on Geo location. I get the following
error/exception : can't find special index: 2d for

I ran the .getIndexes() on the collection and here is the output of
it:

[
{
"v" : 1,
"key" : {
"_id" : 1
},
"ns" : "myDB.location",
"name" : "_id_"
},
{
"v" : 1,
"key" : {
"loc" : "2d"
},
"ns" : "myDB.location",
"name" : "loc_2d"
}
]


I cant really figure out what is going wrong. Has anyone faced this
issue before??

Thank you.

Ayman Natsheh

unread,
Nov 14, 2011, 2:51:22 AM11/14/11
to mongodb-user
The Mongo I am using is:

MongoDB version: 2.0.0

Nat

unread,
Nov 14, 2011, 4:39:26 AM11/14/11
to mongod...@googlegroups.com
What are the query and the sample data?

Ayman Natsheh

unread,
Nov 14, 2011, 7:22:32 AM11/14/11
to mongodb-user
Hi Nat,

here is the query and the error:

db.spot.find({$and: [ { 'locationList.loc': { $near: [ 31.88957,
35.201856 ], $maxDistance: 0.044248 } } ]})
error: {
"$err" : "can't find special index: 2d for: { $and:
[ { locationList.loc: { $near: [ 31.88957, 35.201856 ], $maxDistance:
0.044248 } } ] }",
"code" : 13038
}



following is the index :
{
"v" : 1,
"key" : {
"locationList.loc" : "2d"
},
"ns" : "KanitiKanitiProd.spot",
"name" : "locationList.loc_2d"
}



Please note that when I remove the $and from the query, it works fine,
as follows:
db.spot.find({ 'locationList.loc': { $near: [ 31.88957, 35.201856 ],
$maxDistance: 0.044248 } })

Nat

unread,
Nov 14, 2011, 8:29:50 AM11/14/11
to mongod...@googlegroups.com

Ayman Natsheh

unread,
Nov 14, 2011, 9:04:01 AM11/14/11
to mongodb-user
It is Exactly the same problem, but I need to use the $and.

There must be something wrong with the index I have. Could it be from
that?

Spencer T Brody

unread,
Nov 14, 2011, 4:41:50 PM11/14/11
to mongod...@googlegroups.com
It is currently not possible to do geo queries in $and or $or statements.  There is an open feature request to add this support, you can track the progress here: https://jira.mongodb.org/browse/SERVER-3984.

In the meantime, would it be possible to rewrite your query to not use $and?  What is the full query you're trying to do?

Ayman Natsheh

unread,
Nov 19, 2011, 7:16:00 AM11/19/11
to mongodb-user
Thank you for the help.
The only solution was to rewrite my query without the use of $and.

Actually my query was made from Morphia library that I use in JAVA,
and it was challenging to find a way to avoid it using the $and. My
solution was to use the $where when making many criteria on the same
field.

Thank you for the help! and sorry for replying back late

Reply all
Reply to author
Forward
0 new messages