3***@qq.com
3***@qq.com
  • 发布:2025-03-21 20:43
  • 更新:2025-03-21 20:43
  • 阅读:48

关于数据库的嵌套计算

分类:uniCloud

a表的表结构是这样的{
"bsonType": "object",
"required": [], // 如果有必填字段,请在此处添加。
"permission": {
"read": true,
"create": true,
"update": true,
"delete": true
},
"properties": {
"_id": {
"bsonType": "objectId", // MongoDB 的 _id 通常是 objectId 类型。
"description": "ID,系统自动生成"
},
"产品ID": {
"bsonType": "string"
},
"产品名称": {
"bsonType": "string"
},
"规格": {
"bsonType": "string"
},
"单位": {
"bsonType": "string"
},
"bom": {
"bsonType": "array",
"items": { // 定义数组中每个元素的结构。
"bsonType": "object",
"required": ["产品ID"], // 根据业务需求定义必填字段。
"properties": {
"产品ID": {
"bsonType": "string",
"foreignKey": "test.产品ID", // 使用 foreignKey 表示关联。
"description": "关联产品信息!"
},
"shul": {
"bsonType": "double",
"defaultValue": 0
}
}
}
}
}
}
b表的表结构是这样的{
"bsonType": "object",
"required": [], // 如果有必填字段,请在此处添加。
"permission": {
"read": true,
"create": true,
"update": true,
"delete": true
},
"properties": {
"_id": {
"bsonType": "objectId", // MongoDB 的 _id 通常是 objectId 类型。
"description": "ID,系统自动生成"
},
"产品ID": {
"bsonType": "string"
},
"数量":{
"bsonType": "double"

        }  
}  

}
}

我想要生成一个查询表,a表中的产品ID值和a表中bom数组里的元素中的产品ID值相等时,产品名称、规格相对应的自动添加到bom数组中,bom数组中的shul的值是他本身的值和b表中的值相乘的结果,最后我只要查询出这个新的bom数组的就可以了,求教下代码怎么写

2025-03-21 20:43 负责人:无 分享
已邀请:

要回复问题请先登录注册