我有这个数据[ { "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来获取特定的产品。
这就是我所尝试的,但它给出了错误的数据
@Repository
public interface UserRepository extends MongoRepository<User, String>
{
Product findByproducts_productId(String productId);
}发布于 2019-03-23 02:11:29
我认为你可以使用下面的查询。
@Query(findByproductsByUserIdAndproductId= "{ 'users.id‘:?0,'products.id’:?1 }") List Query( String userId,String productId);
https://stackoverflow.com/questions/55305189
复制相似问题