node.js - 填充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"
我的问题是,我怎样才能在一个分销商中只获取每个角色的用户数据?
解决方案
推荐阅读
- postgresql - 使用 Postgres 在 Google App Engine 上运行 API
- javascript - 检查类是否是类的子类而不实例化
- c# - char8 和 uchar8 等效
- flutter - Flutter - 无法在 android 上安装 apk
- linkedin-api - 如何从 LinkedIn Voyager API 获取已读回执?
- c++ - 调用函数指针时 CUDA 内核崩溃
- ruby-on-rails - Rails 新手尝试将月份和年份从表单传递到 url
- visual-studio-code - 如何在 VSCode 中禁用风筝提示片段设置?
- php - 无法在 PHP Laravel 项目中显示 JPEG 图像
- node.js - 存储文件(pdf),因此只有经过身份验证的用户才能访问它们(使用 nextjs)