【发布时间】:2020-09-05 20:36:09
【问题描述】:
以下查询不适用于 mongo 存储库 -
@Query(value = "{ 'items' : {$elemMatch : {'attributes' : {$all : [/^?0/i]}}}}")
List<MenuEntity> findMenuByItemAttribute(String attrName);
问题似乎出在我在注释中传递 ?0 的位置。我需要在某处传递引号吗?
db.menus.find({ 'items' : {$elemMatch : {'attributes' : {$all : [/^sav/i]}}}})
以上查询在 mongo shell 中返回结果
文档结构-
db.menus.findOne()
{
"_id" : ObjectId("5cf25412326c3f4f26df039b"),
"restaurantId" : "301728",
"items" : [
{
"itemId" : "CEBM4H41JR",
"name" : "Crun Chicken",
"imageUrl" : "",
"price" : 572,
"attributes" : [
"Tasty",
"Spicy"
]
},
{
"itemId" : "53Q0XS3HPR",
"name" : "Devils Chicken",
"imageUrl" : "",
"price" : 595,
"attributes" : [
"Gravy",
"Salty"
]
}
}
【问题讨论】:
标签: java mongodb spring-boot mongorepository