小编Wha*_*les的帖子

使用ObjectID的Spring Data Mongo自定义存储库查询

我有一个要实现为Spring Mongo存储库的mongo查询

db.collection.find({ 'items': 
    { $elemMatch: { 
        'refund.$id' :  ObjectId('5638cab2e4b07ff212618d7e') 
        } 
    }
}) 
Run Code Online (Sandbox Code Playgroud)

我的存储库界面是

@Query("{ 'items': { $elemMatch: { 'refund.$id' :  ObjectId(?0) } } }")
RMA findRMAByItemRefund(String refundId);
Run Code Online (Sandbox Code Playgroud)

抛出JSONParseException

Caused by: com.mongodb.util.JSONParseException: 
{ 'items': { $elemMatch: { 'refund.$id' :  ObjectId("_param_0") } } }
                                       ^
    at com.mongodb.util.JSONParser.parse(JSON.java:216)
Run Code Online (Sandbox Code Playgroud)

java spring spring-mvc mongodb spring-data-mongodb

6
推荐指数
1
解决办法
7270
查看次数

标签 统计

java ×1

mongodb ×1

spring ×1

spring-data-mongodb ×1

spring-mvc ×1