如何在另一个数组中的对象中插入String类型的数据?
以下是我的数组:
productRequirements: [{
question: "What type of Business Bag do you need?",
type: "checkbox",
specifications: [
"Luggage Bag",
"Handbag",
"Shoulder Bag",
"Soft Bag",
"Laptop Bag",
"Tote Bag",
"Not Sure",
"Others"]
}, {
question: "What kind of logo do you prefer on your bag?",
type: "radio",
specifications: [
"OEM",
"Embossed",
"Debossed",
"Printed",
"Customized",
"Not Sure",
"Others"]
}]
我想逐个在specifications
中插入字符串,我正在尝试以下代码:
Products.update({
_id: productId,
"productSpecifications.Specification": listing["Specification"]
}, {
$push: {
"productSpecifications.$.Options": {
Options: listing["Options"]
}
}
})
是插入对象而不是字符串。我怎样才能纠正它?