首页 > 解决方案 > 带有@Field 的字段未转换为正确的值

问题描述

我有一个文档,其中一个字段的名称被@Field 覆盖:

public User {
@Id
private String id;
private String username;


@Field("profiles")
private List<BusinessProfile> 
businessProfiles;
...
}

和一个带有匹配操作的聚合操作如下:

match(where("businessProfiles.services").elemMatch(Criteria.where("category").is(serviceCategory)))

但是,在这最终生成的查询中,businessProfiles 不会转换为配置文件。这是我从日志文件中得到的查询:

Executing aggregation: [ { "$match" : { "businessProfiles.services" : { "$elemMatch" : { "category" : "Cloud_Initiation"}}}} ...]

这种行为似乎很奇怪。这应该以这种方式工作吗?谢谢。

标签: springmongodbspring-data-mongodb

解决方案


字段映射仅用于TypedAggregation提供映射源类型。

TypedAggregation<Product> agg = newAggregation(User.class, 
    match(where("businessProfiles.services")...

我创建了DATAMONGO-2310来改进该领域的文档。


推荐阅读