首页 > 解决方案 > 填充NodeJs MongoDB后获取数据

问题描述

这是我的架构 在此处输入图像描述

我有这样的人口查询

 let population = [{model: Customer, path: 'customer'}, {model: Role, path: 'role', select: 'user', populate: {model: User, path: 'user'}}]

这个查询的结果是这样的

 "data": [
            {
                "isactive": false,
                "created_at": "2020-01-20T07:57:36.251Z",
                "_id": "5e255e7fe560893f0c30f9ce",
                "code": "4",
                "name": "DISTRIBUTOR 1",
                "contact": "ronald",
                "phone": 812117562425,
                "email": "info@test.com",
                "tipe": "A",
                "__v": 0,
                "customer": null,
                "role": {
                    "_id": "5e255e96e560693f1c30f2cf",
                    "distributor_id": "5e255e2fe522083f0c30f9ce",
                    "user": {
                        "isactive": false,
                        "last_login": "2020-01-21T02:15:55.073Z",
                        "superUser": false,
                        "_id": "5e255fb6e560893f0c30f9d0",
                        "role_id": "5e255e96e560893f0c30f9cf",
                        "name": "yogi",
                        "description": "Admin1"

我的问题是,我怎样才能在一个分销商中只获取每个角色的用户数据?

标签: node.jsmongodbpopulation

解决方案


推荐阅读