如何使用来自另一个列表的 findById => 来自 MainList 的子列表从 MongoDB 检索特定的元素列表?

How do I retrieve particular List of element from MongoDB Using findById from another List => SubList from MainList?

如何检索此列表:

[
    {
        "id": "1",
        "title": "Jordanian Mansaf",
        "description": "content: blah blah blah, method: blah blah blah",
        "imagePath": "Mansaf imagePath",
        "created": "2022-03-12T04:42:39.818+00:00"
    },
    {
        "id": "2",
        "title": "Jordanian Maklobah",
        "description": "content: blah blah blah, method: blah blah blah",
        "imagePath": "Maklobah imagePath",
        "created": "2022-03-12T04:43:10.869+00:00"
    },
    {
        "id": "3",
        "title": "Suadi Kabsah",
        "description": "content: blah blah blah, method: blah blah blah",
        "imagePath": "Kabsah imagePath",
        "created": "2022-03-12T04:43:36.470+00:00"
    },
    {
        "id": "4",
        "title": "Briani",
        "description": "content: blah blah blah, method: blah blah blah",
        "imagePath": "Briani imagePath",
        "created": "2022-03-12T04:44:03.227+00:00"
    },
    {
        "id": "5",
        "title": "Zarb",
        "description": "Contnent: blah blah blah, Method: blah blah blah",
        "imagePath": "Zarb_imagePath",
        "created": "2022-03-12T11:43:26.330+00:00"
    }
]

传递这个list [id]时:

[
    {
        "id": "1",
        "title": "Cat1",
        "imagePath": "Cat1_imagePath",
        "created": "2022-03-12T04:42:39.818+00:00"
    },
    {
        "id": "2",
        "title": "Cat2",
        "imagePath": "Cat2_imagePath",
        "created": "2022-03-12T04:43:10.869+00:00"
    },
    {
        "id": "3",
        "title": "Cat3",
        "imagePath": "Cat3_imagePath",
        "created": "2022-03-12T04:43:36.470+00:00"
    },
    {
        "id": "4",
        "title": "Cat4",
        "imagePath": "Cat4 imagePath",
        "created": "2022-03-12T04:44:03.227+00:00"
    },
    {
        "id": "5",
        "title": "Food Cat5",
        "imagePath": "Cat5_imagePath",
        "created": "2022-03-12T11:43:26.330+00:00"
    }
]

我刚刚找到了我的问题的答案,如下所示:

In the mongo repository just declare a custom find method:


 @Repository
public interface RecipeRepository extends MongoRepository<RecipeContainer, String> {
   List<RecipeContainer> findAllById(String id);
}

Then use it as a normal find method => [query] in your business logic layer and controller layer.