node.js - 一对多关系
问题描述
我有以下情况,不知道如何解决。我尝试了不同的方式,但没有成功。我什至不知道这是否可能。我希望使用带有映射(或减少)功能的 CouchDB 视图来完成此操作。我想按照以下示例在 CouchDB 中实现一对多关系:
{
"_id": 1,
"name" : "Me",
"doctype" : "employee"
},
{
"_id" : 2,
"name" : "MeAgain",
"doctype" : "employee"
},
{
"_id" : 3,
"doctype": "holidayrequest",
"startdate": "01/25/2021",
"requesterid": "1"
},
{
"_id" : 4,
"doctype": "holidayrequest",
"startdate": "01/16/2021",
"requesterid": "1"
},
{
"_id" : 5,
"doctype": "holidayrequest",
"startdate": "04/16/2021",
"requesterid": "2"
},
{
"_id" : 6,
"doctype": "holidayrequest",
"startdate": "04/25/2021",
"requesterid": "2"
}
我希望结果是:
{
"_id": 1,
"name" : "Me",
"doctype" : "employee",
"holidays":[
{
"_id" : 3,
"doctype": "holidayrequest",
"startdate": "01/25/2021",
"requesterid": "1"
},
{
"_id" : 4,
"doctype": "holidayrequest",
"startdate": "01/16/2021",
"requesterid": "1"
}
]
},
{
"_id" : 2,
"name" : "MeAgain",
"doctype" : "employee",
"holidays":[
{
"_id" : 5,
"doctype": "holidayrequest",
"startdate": "04/16/2021",
"requesterid": "2"
},
{
"_id" : 6,
"doctype": "holidayrequest",
"startdate": "04/25/2021",
"requesterid": "2"
}
]
}
这可以做到吗?
解决方案
推荐阅读
- sql - 根据特定键选择行
- c# - C#,如何将 TextBox 值插入 DataGridView 当前单元格(标记为一个)?
- c# - 初始帐户创建/登录后,Firebase 数据库权限被拒绝
- javascript - 如何在批量导入中使用 sequelize findorcreate?
- firebase - 渲染应用程序时如何从firestore获取集合并设置为vuex状态?
- html - Bootstrap 4 - 4 个按钮(2 x 行)在同一个按钮组响应
- python - Python:TypeError 参数数量错误的原因
- json - 将 JSON 数组映射到 Spring Hibernate 数据库 (H2)
- javascript - VelocityJS 2.0.5 - SkewX
- ecm - 文档未在 Opentext Archive Server 10.5 中归档