春のデータとmongo dbデータベースを使用してバックエンドを開発しています。
次のクラスを取得しました
@Document
public class Place
{
@Id
private String id;
@GeoSpatialIndexed
private Double[] location;
private int[] category;
//gets and sets
}
だから、選択したカテゴリを持つポイントの近くの場所を取得するためのクエリを作成したいので、これを得ました:
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
}
しかし、これは結果を返していません。クエリであることはわかっています。
db.place.find( { category: { $all: [ categoryID, categoryID2 ] } } );
うまく機能し、geoNear は問題ではありません。
ばかげた質問ですが、Mongo の Spring Data のドキュメントと例は非常に基本的なものであり、ヘルプや優れたチュートリアルやドキュメントへのリンクが役立つ場合があります。:)