Java (聚合)Can';找不到org.springframework.data.mongodb.core.geo.GeoJsonPoint类的编解码器
你能帮我做一下吗 我在下面给出的存储库中有上述错误Java (聚合)Can';找不到org.springframework.data.mongodb.core.geo.GeoJsonPoint类的编解码器,java,spring,mongodb,aggregation,Java,Spring,Mongodb,Aggregation,你能帮我做一下吗 我在下面给出的存储库中有上述错误 @Repository("polygonQueryRepository") @RequiredArgsConstructor public class PolygonQueryRepositoryImpl extends PolygonRepository { @Autowired private MongoOperations operations; public List<DBObject> findP
@Repository("polygonQueryRepository")
@RequiredArgsConstructor
public class PolygonQueryRepositoryImpl extends PolygonRepository {
@Autowired
private MongoOperations operations;
public List<DBObject> findPolygonsMatchingGivenPointAndInputAggregate(Double lat, Double lng, String band) {
GeoJsonPoint point = new GeoJsonPoint(lat, lng);
MatchOperation operation = match(Criteria.where("location").intersects(point).and("attributes.band").regex(band));
Aggregation aggregation = newAggregation(Polygon.class,
unwind("attributes.transponders"),
operation);
AggregationResults<DBObject> result =
operations.aggregate(aggregation,"Polygon",DBObject.class);
return result.getMappedResults();
}
}
你有什么建议吗?你对这一行很熟悉:
MongoClientOptions options = MongoClientOptions
.builder()
.codecRegistry(MongoClient.getDefaultCodecRegistry())
.build();
但要使用GeoJsonPoint类,您需要实现接口,然后按照以下方式注册它:
CodecRegistry registry = CodecRegistries.fromRegistries(
CodecRegistries.fromCodecs(new GeoJsonPointCodec()), // the codec you need to implement
MongoClient.getDefaultCodecRegistry()
);
您可以在“选项生成器”中使用此注册表。您已接近这一行:
MongoClientOptions options = MongoClientOptions
.builder()
.codecRegistry(MongoClient.getDefaultCodecRegistry())
.build();
但要使用GeoJsonPoint类,您需要实现接口,然后按照以下方式注册它:
CodecRegistry registry = CodecRegistries.fromRegistries(
CodecRegistries.fromCodecs(new GeoJsonPointCodec()), // the codec you need to implement
MongoClient.getDefaultCodecRegistry()
);
您可以在选项生成器中使用此注册表。cbartosiak,非常感谢您的回答!这对我帮助很大。但是解决方法非常不明显!:) 事实上,注册是必需的,但在将聚合接口更改为之前,我无法注册
AggregationResults<AggregatedPolygon> result = template.aggregate((TypedAggregation<?>) aggregation, AggregatedPolygon.class);
AggregationResults=template.aggregate((TypedAggregation)aggregation,AggregatedPolygon.class);
所以我只需要将cast添加到typedaggeration
聚合对象中,并从接口中删除集合名称
这真的很奇怪,但对我来说是这样的 cbartosiak,非常感谢您的回答!这对我帮助很大。但是解决方法非常不明显!:) 事实上,注册是必需的,但在将聚合接口更改为之前,我无法注册
AggregationResults<AggregatedPolygon> result = template.aggregate((TypedAggregation<?>) aggregation, AggregatedPolygon.class);
AggregationResults=template.aggregate((TypedAggregation)aggregation,AggregatedPolygon.class);
所以我只需要将cast添加到typedaggeration
聚合对象中,并从接口中删除集合名称
这真的很奇怪,但对我来说是这样的 非常不言自明。MongoDB不使用
GeoJsonPoint
数据结构。由于这是一个自定义函数,或者至少是在外部库中实现的,因此您需要使用序列化程序进行扩展,或者(在这里有一定的意义)只需提供预期的BSON结构即可。因此建议使用后者,特别是因为“所述函数”的顺序实际上不正确,其中GeoJSON的实际顺序是经度然后纬度。如果没有正确的顺序,MongoDB查询将无法工作。事实上,Mongo以这种方式准确识别经度,然后是纬度。GeoJsonPoint来自org.springframework.data.mongodb.core.geo,所以它与Mongo和Spring的集成有很大的关系,这是不言自明的。MongoDB不使用GeoJsonPoint
数据结构。由于这是一个自定义函数,或者至少是在外部库中实现的,因此您需要使用序列化程序进行扩展,或者(在这里有一定的意义)只需提供预期的BSON结构即可。因此建议使用后者,特别是因为“所述函数”的顺序实际上不正确,其中GeoJSON的实际顺序是经度然后纬度。如果没有正确的顺序,MongoDB查询将无法工作。事实上,Mongo以这种方式准确识别经度,然后是纬度。GeoJsonPoint来自org.springframework.data.mongodb.core.geo-因此它与Mongo和Spring的集成非常相关。非常感谢您的评论!我会努力跟进,然后带着结果回来。不幸的是,我没有运气。在实现编解码器并按照您的建议注册后,我仍然发现相同的错误。我想在某个地方,解码器
对象被默认的编解码器覆盖。您使用哪个版本的Spring数据?我来看看这个,它是SpringDataMongoDB1.10.6 SpringDataCommons 1.13.6,你能给出这种情况下的反编码示例吗?谢谢。非常感谢你的评论!我会努力跟进,然后带着结果回来。不幸的是,我没有运气。在实现编解码器并按照您的建议注册后,我仍然发现相同的错误。我想在某个地方,解码器
对象被默认的编解码器覆盖。您使用哪个版本的Spring数据?我来看看这个,它是SpringDataMongoDB1.10.6 SpringDataCommons 1.13.6,你能给出这种情况下的反编码示例吗?谢谢