Ich habe ein Formular erstellt, wo ich bestimmte Felder habe.Ich habe auch ein Feld, das ein Array von Feldern enthält innerhalb. "Req.body.Lead" Ausgabe des Feldes ist als:So speichern Sie ein Objekt in Mongodb
// 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: '' },
ich kann in einem anderen Objekt das gesamte Objekt speichern, wie:
var address = new Addresses(req.body.lead.business_address_attributes);
Innen mongodb i ein Feld erklärt haben, wie:
business_address_attributes : [Addresses],
//Note: [Addresses] refers to address class
Jetzt, wenn ich versuche das Innere monogdb zu speichern mit folgenden, erhalte ich Fehler, nicht in der Lage führen zu speichern
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 } ]
Ich weiß nicht, wie die problem.Can jemand helfen zu lösen.