如何在 Spring Mongo 模板中使用 includeLocs

How to use includeLocs in Spring Mongo Template

需要在 spring mongo 模板中编写此查询

 "$geoNear": {
         "near": [ -73.9815103, 40.7475731 ],
         "spherical": true,
         "distanceField": "distance",
         "includeLocs": "locs"
      }

特别"includeLocs":"locs"这部分

当前缺少此选项。我打开#3586为其提供支持
同时,您可以执行以下操作。

GeoNearOperation operation = new GeoNearOperation(query, "distance") {

    @Override
    public Document toDocument(AggregationOperationContext context) {

        Document $geoNear = super.toDocument(context);
        $geoNear.put("includeLocs", "distance.location");
        return $geoNear;
    }
}