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

259
Visualizações
Can I send an object to my database from a script without a form submit button?

I've set up some logic to run on a page but instead of console.logging the results, I'd like to send them to my database. Here's the script:

const cookies = document.cookie //https://www.youtube.com/watch?v=8tL5P-RtAH0
    .split(';')
    .map(cookie => cookie.split('='))
    .reduce((accumulator, [key, value]) =>
        ({ ...accumulator, [key.trim()]: decodeURIComponent(value) }),
        {});

const splitCoords = eventCoords.split(',');

if (cookies.event_id == eventID)
    {
        if(confirm('Company A wants to use your current location to briefly checkin. Do you approve?')) {  
            navigator.geolocation.getCurrentPosition(function (position) {
                if ((splitCoords[1] - position.coords.latitude >= -0.009 && splitCoords[1] - position.coords.latitude <= 0.009) && 
                (splitCoords[0] - position.coords.longitude >= -0.009 && splitCoords[0] - position.coords.longitude <= 0.009))
                    {
                        console.log("Guest checked in and is in attendance.")
                    } else {
                        console.log("Guest is not at the event.")
                    }
            })}     else {
                        console.log("The check-in locator was denied.")
                        }}
    else
    {
        console.log("Guest did not check in for this event.")
    }

Here's where I think it gets a little tricky (but I'm new-ish so I may be missing something obvious), for the "guest checked in and is in attendance" line I'd like to send a "Y" to the GUEST part of my Event model:

const eventSchema = new Schema({
  event_name: String,
  venue_name: String,
  artist: {
    type: Schema.Types.ObjectId,
    ref: 'Artist'
  },
  guests: [
    {
      type: Schema.Types.ObjectId,
      attended: String, // this is what should be a "Y" if attended
      ref: 'Guest'
    }
  ],
  },
}, opts);

And here is my guest model for context:

const guestSchema = new Schema({
    phone: Number,
    email: String, 
    event: {
        type: Schema.Types.ObjectId,
        ref: 'Event',
        attended: String //this is what should be a "Y"
    }
});

The guest has a objectID in the DB that I've also stored as a cookie on the browser (because they're not logged in). The first part of my script (at the top) parses the cookies from the page so I can grab them and plug them in to the function.

Is there a way to send a "Y" to the DB against their particular objectID if "the guest is in attendance and has checked in"?

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