Collections - mongodb

8

I have a collection called suspeitosSchema and another call acoesSchema .

suspectsSchema:

const suspeitosSchema = new mongoose.Schema({
  sexo: { type: String },
  etnia: { type: String },
  cumprimentoCabelo: { type: String },
  corCabelo: { type: String },
  altura: { type: String },
  peso: { type: String },
  tipoArma: { type: String },
  armaBranca: { type: String },
  armaDeFogo: { type: String },
  observacao: { type: String }
})

acoesSchema:

const acoesSchema = new mongoose.Schema({
  dataCadastro: { type: Date, default: Date.now },
  fonte: { type: Array, required: true },/*
  bo: { type: String },*/
  numeroBo: { type: Number, required: true },
  imagem: { type: String },
  relato: { type: String, required: true },
  modus: { type: String, required: true },
  falhasApuradas: { type: String, required: true },
  data: { type: Date, required: true }, 
  latitude: { type: String, default: '-27.226520' },
  longitude: { type: String, default: '-52.018375' },
  suspeitos: [suspeitosSchema],
  veiculos: [veiculosSchema],
  tipoAcao: { type: String, required: true, required: true }
})

Note that in the actions collection there is a field called suspeitos , so I can store a suspect's data together with the rest of the data from a form.

However, I need to add more than one suspect per form, I can not do this, does anyone have any idea how I could do it?

    
asked by anonymous 01.12.2017 / 19:58

1 answer

6

It should look like this: suspeitos: [{ type: ObjectId, ref: 'suspeitosSchema' }]

const acoesSchema = new mongoose.Schema({
  dataCadastro: { type: Date, default: Date.now },
  fonte: { type: Array, required: true },/*
  bo: { type: String },*/
  numeroBo: { type: Number, required: true },
  imagem: { type: String },
  relato: { type: String, required: true },
  modus: { type: String, required: true },
  falhasApuradas: { type: String, required: true },
  data: { type: Date, required: true }, 
  latitude: { type: String, default: '-27.226520' },
  longitude: { type: String, default: '-52.018375' },
  suspeitos: [{ type: ObjectId, ref: 'suspeitosSchema' }],
  veiculos: [{ type: ObjectId, ref: 'veiculosSchema' }],
  tipoAcao: { type: String, required: true, required: true }
})
    
12.12.2017 / 14:52