What could be causing the lack of data appearing in my MongoDB database submissions?

Currently, my form successfully posts data to an mLab-hosted database, but the only information that appears is an id number and `"__v": 0'. The form consists of five input fields with corresponding names based on a defined schema. Any suggestions on how to resolve this issue?

Below is the form structure:

<form action="/events" method="POST">
<fieldset>
    <legend>New Event</legend>

    <div class="form-1">
        <div>
            <label for="title">Title</label>
            <input type="text" id="title" name="title" placeholder="Whale Watching">
        </div>
        <div>
            <label for="date">Date</label>
            <input type="text" id="date" name="date" placeholder="7/13">
        </div>
        <div>
            <label for="date">Time</label>
            <input type="text" id="time" name="time" placeholder="9:00am">
        </div>
        <div>
            <label for="price">Price</label>
            <input type="text" id="price" name="price" placeholder="ex. $150">
        </div>
        <div>
            <label for="capacity">Capacity</label>
            <input type="text" id="capacity" name="capacity" placeholder="ex. 12">
        </div>
    </div>
    <button type="submit">Create Event</button>

</fieldset>

Defined model:

const mongoose = require('mongoose');
mongoose.Promise = global.Promise;
const Schema = mongoose.Schema;

const EventSchema = new Schema({
  title: String,
  time: Number,
  date: Date,
  price: Number,
  capacity: Number,
});

const Event = mongoose.model('events', EventSchema);

module.exports = Event;

Associated POST route:

router.post('/events', (req, res) => {
    Event.create(req.body).then(function(events){
        res.send(events);
    });
});

Server setup:

const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
const routes = require('./src/routes/index');

app.set('view engine', 'ejs');
app.set('views', __dirname + '/views');

app.use(bodyParser.json());
app.use(express.static('public'));
app.use(routes);


mongoose.connect('mongodb://junk:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a6ccd3c8cde6c2d597929794929488cbcac7c488c5c9cb">[email protected]</a>:41242/alaska-events');


app.listen(3000, () => {
    console.log('listening on 3000')
  });

Answer №1

My friend provided the solution for me. I'm sending traditional form data without the addition of

app.use(bodyParser.urlencoded({ extended: false }))

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Configuring vue-jest: Does anyone know how to set up aliases for template/script src attributes in Vue?

Dependencies: "@vue/cli-plugin-unit-jest": "^4.5.13", "@vue/test-utils": "^1.2.1", "vue-jest": "^3.0.7" I am dealing with an application that utilizes an alias (referred to as "foo") de ...

Fresh php form for sending a new email communication

Looking for the best way to clear a PHP form after submitting it? I added an onClick event to my input button, but the form still appears filled. Is there a better way to achieve this using an event on the button? echo "<div id='success_page_a ...

Converting a nested JavaScript array into a PHP array

Having a javascript array is how my dilemma starts: foodList = ([apple,10,],[banana,20]) To convert this to a json object and send it to php, I perform the following action: var jsonData = JSON.stringify(foodList); The challenge now is extracting values ...

The presence of certain characters is leading to problems in the console

Similar Question: Escaping a String for JavaScript Usage in PHP? The characters in my text are causing errors. When I input special characters such as: !\"$%^&()-=\'.,:;/?#~/\\>< An error saying "Syntax error ...

Is it possible to save the current state of an execution in JavaScript and pick up where you left off

Is there a way to accomplish this task? I am interested in developing a JavaScript application that has the ability to "pause" and then "resume" execution from a specific point, similar to a checkpoint system. For example: //code.js var abc = 13; checkpoi ...

Using Javascript or ES6, you can compare a nested array object with another array of elements and generate a new array based on

I am dealing with a complicated array structure as shown below sectionInfo = [{id: 1, name:'ma'}, {id: 2, name:'na'}, {id: 3, name:'ra'}, {id: 4, name:'ka'}, {id: 5, name:'pa'}]; abc = [{id:'1' ...

Adjust the size of the wrapper/mask as the browser is resized

Is there a way to adjust the size of my wrapper and mask when the browser is resized? Currently, the mask stops once it's loaded, causing the content to be cut off when scrolling. You can view an example on this site. $(document).ready(function() { ...

Dynamic text input and selection menu with AJAX (PHP and JavaScript)

As a student who is new to Javascript and PHP, I am trying to create a login page for my website that can verify user input in the database using AJAX. For example, when a user enters their username and password, the system should automatically check if t ...

Navigating to a Different Page in React Based on Button Click and Meeting Specific Conditions

Within this particular component, I have implemented a button named Submit. When this button is clicked, it triggers a series of actions: first, it exports the drawing created by the user as a jpeg URL, then sends this image data to another API that genera ...

Show the HTML page returned by the server on the client side

Hey there! I've come across a PHP code snippet that sends back an HTML file as a response. This PHP code makes use of the include method to send the file. When I'm on the client side, I'm employing AJAX. Upon typing console.log(data) (with ...

What method can I use to locate the double quote option within an HTML select element using jQuery?

Here is an example of the select: <select id="id0" name="name0"> <option value='30" size'> 30" size </option> </select> The select contains double quotes. I am trying ...

Adjust picture based on the MaterialUI slider's value

I want to incorporate a discrete Slider component from Material UI into my React web app. The goal is to have the user change a picture every time they adjust the slider value, with the new image displayed in a specific div. I am wondering how I can achiev ...

Issues with router middleware functionality in Node.js hinder proper operations

Currently, I am working with Nodejs and utilizing "Express js". One of the tasks at hand involves implementing a "Router Middleware" function. With my current code setup, whenever I access "http://localhost:3000", the "router middle" functionality is tri ...

Node.js does not support running Bootstrap and CSS, resulting in style not being applied due to the MIME type ('text/html') not being a supported stylesheet MIME type

I attempted to test out the Start Bootstrap Bare template using Node.js and Express. (Link to Start Bootstrap Template) I opted not to make any alterations to the HTML, CSS, and JavaScript files provided with the template. Instead, I created a new index.j ...

Passing a JavaScript variable to PHP through AJAX seems to be a difficult task

Currently, I am attempting to retrieve the user's current location. I have a JavaScript script that fetches the current Latitude and Longitude using AJAX to send those variables to index.php. $(document).ready(function() { if ("geolocation" in navig ...

Tips for cycling through an associative array using integer indices?

No matter where I look, it seems like finding an answer to this question is impossible I've got an array array=["id1" : "somedata", "id2" : "somedata2",....] So I can access it using a special database ID, but what if I want to iterate through this ...

`@keyup.enter event listener will only be triggered upon pressing the Enter key if the focus is on

My login button only seems to work when I press the tab button after entering my email and password. I would like it to work whenever I press the enter key while on the Login page of this VueJS application. This is the HTML template: <template> ...

Express encountered an unexpected error when attempting to navigate to the client directory

I am attempting to send the index.html file from my client directory, located at the same level as my server directory. However, I am encountering the following error: TypeError: undefined is not a function at Object.handle (/myapp/server/routes/routes.js ...

BufferGeometry is not being displayed

After working extensively with BufferGeometry, I considered myself quite familiar with it. However, I am currently facing an issue while trying to create a simple square plane - there is no visible plane, no errors, and everything seems to be set up correc ...

Building a div element within a React function

For an exercise, I need to create an input field and a button. The goal is to display the text from the input field in a div/span below when the button is clicked. If I change the text in the input field and click the button again, the displayed text shoul ...