【发布时间】:2020-07-06 05:48:08
【问题描述】:
我尝试使用以下 @Query 从包含 5 个字段的文档中仅检索 3 个字段。
@Query(value="{'organization':?0,'roleType':?1 }",fields="{'organization' : 0, 'roleType' :0}")
public List<Role> findByOrganizationAndRoleType(String organization, String roleType);
这给了我如下结果。
[
{
organization: null,
firstName: "John",
lastName: "Doe",
nicNo: "5000",
roleType: null
}
]
是否可以省略字段,而不是像上面那样用“null”值显示它们。
【问题讨论】:
-
null来自您的实体类,而不是 MongoDB。也许您需要处理序列化程序忽略null值 How to tell Jackson to ignore a field during serialization if its value is null? -
@Valijon 谢谢,我已经解决了。 :)
标签: mongodb spring-boot spring-data-mongodb