Can't use $and with geospatial queries?

218 views
Skip to first unread message

markdsievers

unread,
Dec 27, 2011, 6:43:55 PM12/27/11
to mongodb-user
This geospatial query executes successfully:

db.place.findOne({ "geometry.centroid": { $near: [ -37.817532,
144.967148 ], $maxDistance: 5.0 }, "identity.type_name":"airport"},
{"identity":1, "geometry":1})

where this query will not

db.place.findOne({ $and :[{"geometry.centroid": { $near: [ -37.817532,
144.967148 ], $maxDistance: 5.0 }},
{"identity.type_name":"airport"}]}, {"identity":1, "geometry":1})

Mongo shell reports the error as

Wed Dec 28 12:39:01 uncaught exception: error {
"$err" : "can't find special index: 2d for: { $and:
[ { geometry.centroid: { $near: [ -37.817532, 144.967148 ],
$maxDistance: 5.0 } }, { identity.type_name: \"airport\" } ] }",
"code" : 13038

db.place.getIndexes() reports the geospatial index is set
{
"v" : 1,
"key" : {
"geometry.centroid" : "2d"
},
"ns" : "dev.place",
"name" : "geometry.centroid_2d"
}

Any suggestions appreciated.

markdsievers

unread,
Dec 27, 2011, 6:50:43 PM12/27/11
to mongodb-user
Using mongo v2.0.2
Message has been deleted

markdsievers

unread,
Dec 27, 2011, 8:48:31 PM12/27/11
to mongodb-user
Can be worked around by having the geospatial criteria outside of the
$and eg

db.place.findOne({$and:[{"fooKey":"forValue"}, {"barKey":"barValue"}],
"geometry.centroid": { $near: [ -37.817532, 144.967148 ],
$maxDistance: 5.0 }}, {"identity":1, "geometry":1})

On Dec 28, 1:40 pm, markdsievers <mark.siev...@gmail.com> wrote:
> Or indeed using the geospatial query as the only criteria in the $and
> operator yields the same result (having only one criteria seems to be
> okay for $and using non-spatial indexes)
>
> db.place.findOne({$and:[{ "geometry.centroid": { $near: [ -37.817532,
> 144.967148 ], $maxDistance: 5.0 }}]}, {"identity":1, "geometry":1})

markdsievers

unread,
Dec 29, 2011, 2:04:18 AM12/29/11
to mongodb-user
Defect / Question opened here https://jira.mongodb.org/browse/SERVER-4572
Reply all
Reply to author
Forward
0 new messages