当我创建像findByName(…)
这样的Spring Data存储库的方法时,一切正常。但是当使用findByField1AndName(…)
Spring Data时,MongoDB仅为最后一个参数生成查询:
{ name : 'qwerty' }
但我预计会产生
{ field1 : 'something', name : 'querty' }
有什么问题?请帮忙。
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);
答案 0 :(得分:1)
不确定是否遗漏了什么。 我尝试了1.0.3和1.0.4,它仍然无法正常工作。现在唯一可用的版本看起来像1.0.1
当我尝试使用1.0.3和1.0.4这样的findByZipCodeAndName时,这就是我在日志中看到的
MongoQueryCreator [DEBUG] Created query Query: { "zipCode" : "test"}, Fields: null, Sort: null
使用1.0.1它按预期工作:
MongoQueryCreator [DEBUG] Created query { "zipCode" : "test" , "name" : "blah"}
显然,在新版本中,只会解释和查询第一个字段。
答案 1 :(得分:0)
你似乎偶然发现了1.0.2和1.1.M1中的bug。修复已经有一段时间了,所以升级到最新版本(1.0.4,1.1 RC1)应该可以解决问题。