I have the following document (Schema):
var CandidatoSchema = new Schema ({
id_login: Schema.Types.ObjectId,
nome: String,
cpf: String,
dataNascimento: Date,
sexo: String,
estadoCivil: String,
endereco: {
endereco: String,
numero: Number,
bairro: String,
complemento: String,
cep: String,
uf: String,
cidade: String
}
});
I have a Form with these fields, when the user clicks the Salvar
button it will send the data to my cadastro
:
on my route record I have a console.log(req.body)
: which shows the data sent.
{ nome: 'NomeSs',
cpf: 'xxx.xxx.xxx-xx',
endereco:
{ endereco: 'rua alameda',
numero: '111',
bairro: 'bairro',
complemento: 'compras',
cep: '111-111' }
I'm having difficulty inserting the data into embedded
documents, in which case you are not inserting the endereco
data.
My role to insert:
exports.Add = function(req, res) {
console.log(req.body);
var person = new Person();
// Tentei usar está linha, mas não funciona...
person.endereco.push(req.body.endereco);
person.save(function(err, person) {
if(err) res.sendStatus(500);
res.sendStatus(201);
});
};
Does anyone have any idea how I can do to insert documents embedded
?