【发布时间】:2018-11-01 14:55:13
【问题描述】:
我使用聚合如下:
final List<AggregationOperation> aggregations = new ArrayList<>();
Polygon polygon = new Polygon(new Point(-26.28125, 42.19231862526141), new Point(100.28125, 64.7157757187955),
new Point(100.28125, 42.19231862526141), new Point(-26.28125, 64.7157757187955));
AggregationOperation match = new MatchOperation(Criteria.where("location").within(polygon));
aggregationOperations.add(match);
aggregations.add(project("_id", "location","distance",User.COLLECTION_NAME)
.and("$geoHash").substring(0,slice).as("geo"));
aggregations.add(group("geo").count().as("count")
.avg("location.lng").as("lon")
.avg("location.lat").as("lat")
.first(User.COLLECTION_NAME).as(User.COLLECTION_NAME));
final Aggregation aggregation = newAggregation(aggregations);
AggregationResults<ClusteredLocation> groupResults =
mongoTemplate.aggregate(aggregation, UserLocation.COLLECTION_NAME, ClusteredLocation.class);
return groupResults.getMappedResults();
正在创建的聚合如下: { "aggregate" : "collection", "pipeline" : [ { "$match" : { "location" : { "$geoWithin" : { "$java" : org.springframework.data. mongodb.core.query.GeoCommand@d502fd15 } } },{“$lookup”:{“from”:“users”,“localField”:“_id”,“foreignField”:“_id”,“as”:“用户“}},{“$project”:{“_id”:1,“位置”:1,“距离”:1,“用户”:1,“geo”:{“$substr”:[“$geoHash ", 0, 3] } } }, { "$group" : { "_id" : "$geo", "count" : { "$sum" : 1 }, "lon" : { "$avg" : " $location.lng" }, "lat" : { "$avg" : "$location.lat" }, "users" : { "$first" : "$users" } } } ] }
我得到如下异常:
org.bson.codecs.configuration.CodecConfigurationException:找不到类 org.springframework.data.mongodb.core.query.GeoCommand 的编解码器。
我在匹配操作中做错了吗?
【问题讨论】:
-
这看起来很像一个错误。似乎
Criteria没有通过QueryMapper将非MongoDB 简单类型传递给驱动程序。我创建了DATAMONGO-1986 来调查这里发生的事情。
标签: mongodb spring-data-mongodb