Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

243
Visualizações
Create object in db AND turn its objectId into a cookie

I'm trying to create an object in a db then store its objectId as a cookie when the guest adds a phone number to my event model.

function

module.exports.addGuest = async (req, res) => {
    const event = await Event.findById(req.params.id);
    const guest = req.body.guest;
    event.guests.push(guest);
    await event.save();
    console.log(guest, req.body.guest._id );
    res.cookie('guest_id', `${guest._id}`);
    res.cookie('event_id', `${event._id}`);
    res.redirect(`/events/${event._id}`);
}

the console.log above yields { phone: '4444444444' } undefined

event model

const eventSchema = new Schema({
  event_name: String,
  },
  artist: {
    type: Schema.Types.ObjectId,
    ref: 'Artist'
  },
  guests: [
    {
      phone: Number,
      attended: String 
    }
  ],
  created: {
    type: Date,  // Captures both date and time
    default: Date.now
  },
  event_start: {
    type: Date,
    required: [true, 'Date & time of event start required']
    },
  event_end: {
    type: Date,
    required: [true, 'Date & time of event end required']
  },
}, opts);

How do I get the object ID into my controller function so I can store it as a cookie?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda