我已經閱讀了問題Custom method for update query with spring data MongoRepository,我的結果與前面提到的問題中的結果完全相同,唯一的區別是我想通過使用帶@Query注釋的方法來做到這一點。可能嗎?如果是這樣,怎么做?
我有一個物體,如果已匹配確定的標準,我將用一個值更新所有檔案。
我的物體:
@Document("accrual")
public class Accrual extends AbstractEntity {
@Serial
private static final long serialVersionUID = 1175443967269096002L;
@Indexed(unique = true)
private Long numericUserId;
@Indexed(unique = true)
private Long orderIdentifier;
private boolean error;
// sets, gets, equals, hashCode and toString methods
}
我想通過使用Longs 匹配orderIdentifier屬性串列搜索找到的每個檔案來更新布爾錯誤。
如果它在關系資料庫中,我會有一個類似的方法:
@Query(value = "update accrual set error = 0 where order_identifier in :list", nativeQuery = true)
updateErrorByOrderIdentifier(@Param("list") List<Long> orderIdentifiers)
uj5u.com熱心網友回復:
您可以嘗試使用@Query注釋來過濾要更新的檔案并@Update提供實際的更新查詢。
@Query("{ 'orderIdentifier' : { '$in': ?0 } }")
@Update("{ '$set' : { 'error' : 'false' } }")
void updateAllByOrderIdentifier(List<Long> orderIdentifiers);
更多細節可以在這里找到
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/513241.html
標籤:爪哇弹簧靴
上一篇:即使只有一個欄位無效,自定義類驗證器也會拋出所有錯誤
下一篇:FlutterAPI獲取請求掛起
