gpt4 book ai didi

java - 找不到类 org.springframework.data.mongodb.core.query.GeoCommand 的编解码器

转载 作者:太空宇宙 更新时间:2023-11-04 12:42:19 25 4
gpt4 key购买 nike

这是我的代码

Criteria c = new Criteria();
c.andOperator(Criteria.where("country").is(country),
Criteria.where("createTime").lte(wp),
Criteria.where("location").withinSphere(circle),
Criteria.where("titleContent").exists(true));

AggregationOperation match = Aggregation.match(c);
AggregationOperation limit = Aggregation.limit(20);
AggregationOperation sort = Aggregation.sort(new Sort(Sort.Direction.DESC, "createTime"));
AggregationOperation group = Aggregation.group("titleContent").sum("count").as("titleCount").count().as("contentCount");
Aggregation aggregation = Aggregation.newAggregation(match, sort, limit, group);
AggregationResults<TitleRes> result = template.aggregate(aggregation, "post", TitleRes.class);

当我添加Criteria.where("location").withinSphere(circle)

会抛出异常

org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class org.springframework.data.mongodb.core.query.GeoCommand

当我删除Criteria.where("location").withinSphere(circle)

没关系。

我不知道如何处理它。我想获取Sphere内的数据。

最佳答案

我通过使用 geoNear 命令解决了这个问题: https://docs.mongodb.com/manual/reference/command/geoNear/

从条件中删除位置并使用 geoNear 而不是匹配:

        NearQuery near = NearQuery.near(new GeoJsonPoint(request.getLongitude(), request.getLatitude()));
near = near.maxDistance(request.getDistance() / Metrics.MILES.getMultiplier());
near = near.num(2000000);//watch out for max num default restriction
near = near.spherical(true);
Query q = new Query();
q.addCriteria(matchCriteria);
near = near.query(q);
AggregationOperation geoNear = Aggregation.geoNear(near, "location");

关于java - 找不到类 org.springframework.data.mongodb.core.query.GeoCommand 的编解码器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36713914/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com