我正在將 MongoDB 用于我的 spring-boot 應用程式。我需要找到與 ID 串列相對應的檔案串列。我有一個Role集合和一個名為roleIdList的串列。此串列 (roleIdList) 包含需要獲取其檔案的所有角色 ID。
以下是我的查詢:
// My roleIdList is of type List<ObjectId>. I also tried with List<String>
Query query = Query.query(where("_id").all(roleIdList));
List<RolesEntity> rolesEntityList = mongoOperations.find(query, RolesEntity.class);
但是通過上面的查詢,我得到了空的rolesEntityList。誰能幫幫我嗎。
提前致謝!
uj5u.com熱心網友回復:
使用in代替all
Query query = Query.query(where("_id").in(roleIdList));
看:
https://docs.mongodb.com/manual/reference/operator/query/all/ https://docs.mongodb.com/manual/reference/operator/query/in/
uj5u.com熱心網友回復:
您還可以使用: List<RolesEntity> findByRole_IdIn(List<String> roleIdList)
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/381713.html
標籤:MongoDB 弹簧靴 mongodb-查询
