简体   繁体   English

Spring Data MongoDB存储库查询串联如何工作?

[英]How does Spring Data MongoDB repository query concatenation work?

When I create a method of a Spring Data repository like findByName(…) everything works fine. 当我创建像findByName(…)这样的Spring数据存储库的方法时,一切正常。 But when using findByField1AndName(…) Spring Data MongoDB generates query only for the last parameter: 但是当使用findByField1AndName(…) Spring Data MongoDB仅针对最后一个参数生成查询:

{ name : 'qwerty' }

But I expected it generates 但我希望它会产生

{ field1 : 'something', name : 'querty' }

What's the problem? 有什么问题? Please help. 请帮忙。

UPD1: If anyone has such a problem, you can use @Query annotation to manually build your query, example below: UPD1:如果有人遇到此类问题,则可以使用@Query注释手动构建查询,例如以下示例:

@Query("{ region: ?0, product: ?1, direction: ?2, deliveryCondition: ?3, sortament: ?4}")
QuotationKey findByRegionAndProductAndMarketDirectionAndDeliveryConditionAndSortament(
        Geography region, Product product, MarketDirection direction,
        DeliveryCondition deliveryCondition, Sortament sortament);

Not sure if am missing something. 不知道是否缺少什么。 I tried 1.0.3 and 1.0.4 and it still doesn't work. 我尝试了1.0.3和1.0.4,但仍然无法正常工作。 The only working version right now looks like 1.0.1 目前唯一可用的版本看起来像1.0.1

When i tried for something like findByZipCodeAndName with 1.0.3 and 1.0.4, this is what i see in logs 当我尝试使用1.0.3和1.0.4之类的findByZipCodeAndName之类的东西时,这就是我在日志中看到的

MongoQueryCreator [DEBUG] Created query Query: { "zipCode" : "test"}, Fields: null, Sort: null

With 1.0.1 it works as expected: 使用1.0.1可以按预期工作:

MongoQueryCreator [DEBUG] Created query { "zipCode" : "test" , "name" : "blah"}

Apparently in the new releases only the first field is interpreted and queried for. 显然,在新版本中,仅解释和查询第一个字段。

It seems you stumbled over a bug present in 1.0.2 and 1.1.M1. 看来您偶然发现了1.0.2和1.1.M1中的错误 The fixes have been out for a while so upgrading to a recent version (1.0.4, 1.1 RC1) should do the trick. 修复程序已经发布了一段时间,因此升级到最新版本(1.0.4,1.1 RC1)应该可以解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Spring Data MongoDB存储库中查询日期? - How do I query for dates in Spring Data MongoDB repository? 如何使用 Spring 数据 MongoDB 存储库查询大于嵌入的文档? - How to query with greaterThan for an embedded document using Spring Data MongoDB Repository? Spring Data和MongoDB存储库 - 如何创建更新查询? - Spring Data and MongoDB repository - how to create an update query? 使用Spring Data MongoDB中的List参数进行存储库查询 - Repository query with a List parameter in Spring Data MongoDB Spring Data REST:MongoDB存储库的自定义查询 - Spring Data REST : custom query for MongoDB repository 存储库的 Spring JPA 数据扫描不起作用 - Spring JPA Data scanning for repository does not work MongoDB 和 Spring:如何在一个存储库查询中正确查询两个字段? - MongoDB and Spring: How to correctly query with two fields in one repository query? 在spring data mongodb存储库中的@Query注释中使用$或运算符 - Use $or operator in @Query annotation in spring data mongodb repository 使用Spring Data MongoDB存储库添加可选的查询参数 - Add optional query parameter using spring data mongodb repository 如何在Spring Data MongoDB存储库的查询方法中使用投影类型? - How to use projecting types in Spring Data MongoDB repository's query methods?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM