Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

258
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!