SpringData MongoDB 使用投影 [英] SpringData MongoDB Using projection

查看:28
本文介绍了SpringData MongoDB 使用投影的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

他们是否可以通过任何方式使用 mongodb 投影功能从文档中获取选定的字段.

Is their any way via which I can use mongodb projection feature to fetch selected fields from the document.

在网上搜索了一整天也没有找到任何线索.

Even after searching for whole day on internet not able to find any clue.

推荐答案

这里是 有关存储库的文档的相关部分.还有 关于查询文档的部分 有一个简短的提及.

Here's the relevant section of the docs concerning repositories. Also the section on querying documents has a brief mention of it.

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

When using MongoOperations you can use the Query instance to restrict the result to certain fields:

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.

I've filed DATAMONGO-839 to improve the discoverability of this and also polish the JavaDoc of the Query class.

这篇关于SpringData MongoDB 使用投影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆