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

发布于 2025-01-13 11:38:20 字数 2069 浏览 0 评论 0原文

如何检索此列表:

[
    {
        "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"
    }
]

传递此列表[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"
    }
]

How To Retrieve this list:

[
    {
        "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"
    }
]

When passing this 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"
    }
]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

难理解 2025-01-20 11:38:20

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

在 mongo 存储库中只需声明一个自定义查找方法:


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

然后将其用作普通查找方法 => [查询]在您的业务逻辑层和控制器层。

I just figured out an answer for my question and it's as follows:

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文