spring - Error during use $within operator with $elemMatch -
i'm using spring-data-mongodb (version 1.0.2.release) , mongodb (version 2.2). have object contain list of object location. classes following:
public class { @id private objectid id; private list<location> places; //getter , setter } public class place { private string name; private string description; @geospatialindexed private double[] location; //getter , setter }
i need find objects specific location. tried use operators $within , $elemmatch following:
@query(value = "{'places' : { $elemmatch: { location: {'$within' : {'$center' : [?0, ?1]} } }}}") public list<a> findbylocation(point location, double radius);
when run query, receive following exception:
org.springframework.data.mongodb.uncategorizedmongodbexception: can't find special index: 2d for: { places: { $elemmatch: { location: { $within: { $center: [ { x: 41.904159, y: 12.549132 }, 0.07000000000000001 ] } } } } }; nested exception com.mongodb.mongoexception: can't find special index: 2d for: { places: { $elemmatch: { location: { $within: { $center: [ { x: 41.904159, y: 12.549132 }, 0.07000000000000001 ] } } } } }
any suggestions?
regards
apparently there's no 2d index on location
attribute, , mongodb requires such index present. don't know if spring should creating index itself, if doesn't, can create index via
db.collection.ensureindex({"location":"2d"})
where collection
replaced name of collection.
Comments
Post a Comment