[英]How to Get Only Matched Result from An Array Field of Document in Mongo Using Spring Data
[英]How to retrieve only specific field of a document with Spring Data Mongo DB?
例如,我有一个包含以下文档的集合:
class Group {
@Id
@Field( '_id' )
UUID id
@Field( 'title' )
String title
}
我有一个存储库: interface GroupRepository extends MongoRepository<Group, UUID> { }
如何检索所有标识符的列表? 我不想检索所有文档,然后收集 ID。 我想要一个方法,如: List<UUID> findAllGroupIds()
。 如果没有Criteria
显式实现,是否有可能? 我尝试使用@Query
,但没有给出结果。
您可以使用 MongoDB 聚合框架来检索 ID 列表。
Aggregation agg = newAggregation(stages.add(project("_id")));
AggregationResults<UUID> ids = mongoOperation.aggregate(agg,
"Group", UUID.class);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.