我创建了一个表单,其中包含某些字段。我还有一个包含字段数组的字段。该字段的“req.body.lead”输出如下:
// output of console.log("req.body.lead",req.body.lead);
business_address_attributes:
{ address_type: 'Business',
street1: 'Street 1...',
street2: 'Street 2...',
city: 'City...',
state: 'State...',
zipcode: 'Zip Code...',
country: '' },
我可以将整个对象存储在另一个对象中:
var address = new Addresses(req.body.lead.business_address_attributes);
在 mongodb 中,我已将一个字段声明为:
business_address_attributes : [Addresses],
//Note: [Addresses] refers to address class
现在,当我尝试使用以下方法存储内部 monogdb 时,出现错误,无法保存线索
var lead = new Leads(req.body.lead);
var address = new Addresses(req.body.lead.business_address_attributes);
lead.business_address_attributes.$push(address);
lead.save();
// console.log(lead.business_address_attributes) now gives following output:
[ { address_type: 'Business',
street1: 'Street 1...',
street2: 'Street 2...',
city: 'City...',
state: 'State...',
zipcode: 'Zip Code...',
country: '',
_id: 4f857a2e491383dc64000008 } ]
我不知道如何解决这个问题。有人可以帮忙。