SpringData MongoDB Using projection

冷暖自知 提交于 2019-12-21 18:01:47

问题


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.


回答1:


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

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(…);

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



来源:https://stackoverflow.com/questions/21460155/springdata-mongodb-using-projection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!