SpringData MongoDB使用投影

时间:2014-01-30 15:10:27

标签: spring-data spring-data-mongodb

他们可以通过哪种方式使用mongodb投影功能从文档中获取所选字段。

即使在互联网上搜索一整天也找不到任何线索。

1 个答案:

答案 0 :(得分:6)

以下是有关存储库的文档的relevant sectionsection on querying documents也简要提到了它。

使用MongoOperations时,您可以使用Query实例将结果限制为某些字段:

Query query = Query.query(Criteria.where("lastname").eq("…"));
// Configure the field spec you want to use for this query
query.fields().include(…).slice(…);

我已经提交DATAMONGO-839以提高其可发现性,并且还对Query类的JavaDoc进行了改进。