0
var estadoSchema = Schema({
estado_nome: String
});
var cidadeSchema = Schema({
cidade_nome: String,
estado_reference: [{ type: Schema.Types.ObjectId, ref: 'Estados'}]
});
이 디자인 스키마, 그리고 데이터베이스에 포함 아래, 나는이 문제를 삽입 시간에 반복, 이상이 존재하지 않는 경우에만 schma 상태를 만들 수있을 것이라고 스키마 상태에 관한 한, 스키마 도시를 참조로 상태와 연관시킵니다. 스키마 생성. estadoSchema
에 estado_nome
에서몽구스가 채울
Estado.create(req.body)
.then(function(estado){
Cidade.create({cidade_nome: cidade, cidade_reference: [estado._id]})
.then(function(cidade){
res.status(201).json(cidade);
}, function(erro){
res.status.json(erro)
});
res.status(201).json(estado);
}, function(erro){
res.status.json(erro)
});