【发布时间】:2021-04-04 12:11:35
【问题描述】:
我有一个架构和一个数组
这是我的架构
const schema = new Schema({
distributor_id: {
type: String
},
user_id: {
type: String
},
customer_id: {
type: String
},
problem: {
type: Number,
required: true
},
note: {
type: String,
required: true
},
created_at: {
type: Date,
required: true
},
created_by: {
type: String,
required: true
},
updated_at: {
type: Date
},
updated_by: {
type: String
},
}
这是我的数组数据
let problem_data = [{
value: 1,
label: 'error bill',
},{
value: 2,
label: 'error system',
},{
value: 3,
label: 'error connection',
}]
我的结果数据是这样的:
"_id": "5fe86f3d6ff4936d7344d245",
"user_id": "5fa4f1c85d68ba373e2fb0b9",
"customer_id": "5f44e031cb22f81906cc1c6a",
"problem": 1,
我想要的结果是这样的
"_id": "5fe86f3d6ff4936d7344d245",
"user_id": "5fa4f1c85d68ba373e2fb0b9",
"customer_id": "5f44e031cb22f81906cc1c6a",
"problem": {
value: 1,
label: 'error bill'
},
我的问题是是否可以基于数组填充猫鼬模式? 如果可能的话你们如何解决这个问题?或者我可以问一些关键字吗?
【问题讨论】:
标签: node.js arrays mongoose populate mongoose-populate