首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring Boot mongoRepository查询

Spring Boot mongoRepository查询
EN

Stack Overflow用户
提问于 2019-03-23 01:45:38
回答 1查看 45关注 0票数 0

我有这个数据[ { "id": "3", "name": "Lakshya2", "email": "lakshya.punhani2@gmail.com", "products": [ { "id": "2", "description": "qwerty", "rate": "20", "name": "AC" } ] }, { "id": "1", "name": "Lakshya", "email": "lakshya.punhani@gmail.com", "products": [ { "id": "3", "description": "qwerty", "rate": "20", "name": "AC" }, { "id": "2", "description": "desc", "rate": "10", "name": "BBG" } ] } ]

我对spring boot和mongo db也是新手,所以我只需要知道如何通过用户id和产品id来获取特定的产品。

这就是我所尝试的,但它给出了错误的数据

代码语言:javascript
复制
@Repository
public interface UserRepository extends MongoRepository<User, String>
{   
    Product findByproducts_productId(String productId);
}
EN

回答 1

Stack Overflow用户

发布于 2019-03-23 02:11:29

我认为你可以使用下面的查询。

@Query(findByproductsByUserIdAndproductId= "{ 'users.id‘:?0,'products.id’:?1 }") List Query( String userId,String productId);

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55305189

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档