【问题标题】:SpringData MongoDB Using projectionSpringData MongoDB 使用投影
【发布时间】:2014-01-30 15:10:26
【问题描述】:

他们有什么方法可以让我使用 mongodb 投影功能从文档中获取选定的字段。

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

【问题讨论】:

    标签: spring-data spring-data-mongodb


    【解决方案1】:

    这是关于存储库的文档的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。

    【讨论】:

    • 感谢您的 cmets 奥利弗。根据 spring 数据文档,不支持投影,但它存在于 Spring 数据的新候选版本中。
    • 这两个链接都是404。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-08
    • 1970-01-01
    • 1970-01-01
    • 2017-05-24
    • 2015-02-01
    • 1970-01-01
    相关资源
    最近更新 更多