I’m developing a back end with spring data and a mongo db database.
I got the following class
@Document
public class Place
{
@Id
private String id;
@GeoSpatialIndexed
private Double[] location;
private int[] category;
//gets and sets
}
So I want to made a query to get the places near a Point that have the selected categories, So I got this:
public List<Place> getPlacesNear(Double[] location, int[] category){
NearQuery geoNear = NearQuery.near(location[0],location[1],Metrics.KILOMETERS).maxDistance(KM_DISTANCE);
Query categoryQuery = new Query(new Criteria("category").all(category));
geoNear.query(categoryQuery);
GeoResults<Place> geoNearResult = mongoTemplate.geoNear(geoNear, Place.class);
//return results
}
But this isn’t returning any results, I know that the query.
db.place.find( { category: { $all: [ categoryID, categoryID2 ] } } );
Works well and the geoNear isn’t the problem.
Is a silly question but the documentation and examples of the Spring Data for Mongo are very basic, any help or a link for a good tutorial or documentation could be helpful, thanks! 🙂
I found the problem instead of passing
being category a int[], I pass a idCategory,idCategory2
and it works great 🙂