首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >对象内对象数组中的猫鼬

对象内对象数组中的猫鼬
EN

Stack Overflow用户
提问于 2022-04-02 06:11:15
回答 1查看 34关注 0票数 0

下面是我的mongpdb json文档

代码语言:javascript
复制
{
        categoryId: '1',
        categoryName: 'Outdoors Equipments',
        items: [
            {
                itemId: '1',
                itemName: 'Camping Tent',
                itemDescription: 'A tent is a shelter consisting of sheets of fabric or other material draped over, attached to a frame of poles or attached to a supporting rope. While smaller tents may be free-standing or attached to the ground, large tents are usually anchored using guy ropes tied to stakes or tent pegs. First used as portable homes by nomads, tents are now more often used for recreational camping and as temporary shelters.',
                itemImage: '/images/camping-tent.jpeg',
                createdAt: DateTime.now().toLocaleString(DateTime.DATETIME_SHORT)
            },
            {
                itemId: '2',
                itemName: 'Camping Chair',
                itemDescription: 'A tent is a shelter consisting of sheets of fabric or other material draped over, attached to a frame of poles or attached to a supporting rope. While smaller tents may be free-standing or attached to the ground, large tents are usually anchored using guy ropes tied to stakes or tent pegs. First used as portable homes by nomads, tents are now more often used for recreational camping and as temporary shelters.',
                itemImage: '/images/camping-chair.jpeg',
                createdAt: DateTime.now().toLocaleString(DateTime.DATETIME_SHORT)
            },
            {
                itemId: '3',
                itemName: 'Camping Table',
                itemDescription: 'A tent is a shelter consisting of sheets of fabric or other material draped over, attached to a frame of poles or attached to a supporting rope. While smaller tents may be free-standing or attached to the ground, large tents are usually anchored using guy ropes tied to stakes or tent pegs. First used as portable homes by nomads, tents are now more often used for recreational camping and as temporary shelters.',
                itemImage: '/images/camping-table.jpeg',
                createdAt: DateTime.now().toLocaleString(DateTime.DATETIME_SHORT)
            },
        ]
    }

如何基于类别和itemid进行搜索,并使用mongoose和nodejs express返回包含特定项的类别数据和项数据的json。

EN

回答 1

Stack Overflow用户

发布于 2022-04-02 06:28:43

您可以将$elemMatch和$ operator用于此$elemMatch文档 $操作员文件

下面是一个工作示例https://mongoplayground.net/p/GxWp1MIcTcB

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

https://stackoverflow.com/questions/71715277

复制
相关文章

相似问题

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