[英]Spring Boot mongoRepository query
I have this data [ { "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" } ] } ]
我有这个数据
[ { "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" } ] } ]
I am new to spring boot and mongo db as well so i just need to know how to get a particular product by user id and product id. 我是初学者和mongo db的新手,所以我只需要知道如何通过用户ID和产品ID获取特定产品。
This is what I tried but its giving incorrect data 这是我尝试过但它提供的数据不正确
@Repository
public interface UserRepository extends MongoRepository<User, String>
{
Product findByproducts_productId(String productId);
}
I think you can use following query. 我想你可以使用以下查询。
@Query(value = "{ 'users.id' : ?0, 'products.id' : ?1 }") List findByproductsByUserIdAndproductId(String userId, String productId); @Query(value =“{'users.id':?0,'products.id':?1}”)list findByproductsByUserIdAndproductId(String userId,String productId);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.