使用Spring数据和QueryDSL投影在MongoDb查询上 [英] Projection on a MongoDb Query using Spring data and QueryDSL
问题描述
我有一个Spring MVC/Spring Data/Mongo DB应用程序. 我已经根据spring数据文档设置了环境,并且我的存储库工作正常(我可以使用谓词执行查询)
I have a Spring MVC/Spring Data / Mongo DB application. I have setted up my environement according the the spring data documentation and my repositories work fine (I can execute queries with predicates)
我想知道在进行投影时是否可以执行类型安全的查询(使用Spring Data和QueryDSL)(我只需要一个非常大的文档的几个字段).
I was wondering if it was possible to execute a type safe query (using Spring Data and QueryDSL) while making a projection (I want only a few fields of a very big document).
QueryDSL文档提供了一个Hibernate示例,但声明可以在所有模块中完成
The QueryDSL documentation gives an example for Hibernate but states it can be done in all modules QueryDSL Documentation (but I haven't been able to find out how to do it with Mongo)
这是休眠的代码段
class CustomerDTO {
@QueryProjection
public CustomerDTO(long id, String name){
...
}
QCustomer customer = QCustomer.customer;
JPQLQuery query = new HibernateQuery(session);
List<CustomerDTO> dtos = qry.from(customer).list(new QCustomerDTO(customer.id, customer.name));
有什么想法吗?
推荐答案
当前不支持此功能.随时为我们的问题跟踪器添加票证.
This is currently not supported. Feel free to add a ticket for it into our Issue tracker.
Querydsl的Lucene和Mongodb模块仅支持来自查询根的直接投影,但是对于自定义投影,可能会发现一些问题.
The Lucene and Mongodb modules of Querydsl support only direct projections from the query root, but for custom projections something could be figured out.
这篇关于使用Spring数据和QueryDSL投影在MongoDb查询上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!