What is the best way to store information from a form into a Mongodb database?

Currently, I am working on transitioning my todo application to store todos in a MongoDB database instead of a JSON file. After setting up the backend and adjusting my Angular functions to communicate with the backend, I encountered a few issues.

  1. Despite specifying name values in the database, the todo boxes remain empty
  2. Upon page load, the data fetched from the database appears as five empty todo boxes although there are two objects present in the database which is also confirmed through console logs
  3. When performing a post request through Postman, only the parameters generated by MongoDB appear in the database for the todo task instead of the specified name

Below is an excerpt from my server.js file:

// Code snippet for connecting to the MongoDB database
// More server code here...

The issue might be in my controller script which connects the frontend to the backend:

// Relevant JavaScript code related to the frontend-backend connection
// More controller code here...

Any insights on what could be causing these problems?

You can access the main files used for this project on Plunkr

Answer №1

To store additional data fields, you must specify them in the Schema of your Todo Model Schema. If a field is not defined, Mongoose will not include it when saving.

var Todo = mongoose.model('Todo', {
    title: String,
    completed: Boolean,
    deadline: {
        type: Date,
        default: Date.now
    }
});

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

JavaScript code to fetch data from a MySQL database

I am looking to dynamically retrieve data from a MySQL database using PHP in JavaScript variable. The current data is static and I want to make it dynamic by fetching it from the MySQL database without altering the format. Specifically, I need to extract ...

Having issues with the Email type in the JQuery Validation Plugin?

Recently, I set up a Grunt file to consolidate all my libraries and code into a single JS file for inclusion in my website. However, after adding the JQuery Validate plugin (http://jqueryvalidation.org/), I noticed that it's not working as expected. I ...

change styling of ancestor element from descendant element

The code structure I'm working with looks like this:- <li class="container"> <div class="wrap"> <div class="green">...</div> </div> </li> <li class="container"> <div class="wrap"> <di ...

Looking to showcase the current operating hours for today?

It would be great to feature a box on our upcoming library website showing the operating hours for that day. This way, visitors can easily see when the library is open each day they visit the site. Additionally, I plan to include a link for more extensive ...

The Ultimate Guide to Converting Strings into Associative Arrays in PHP

I need help converting a specific string into a proper associative array. To view the string data, please click on the following link: https://maps.googleapis.com/maps/api/geocode/json?latlng=16.539311299999998,80.5820222 The desired outcome is to conve ...

Code for remotely connecting to a server and starting a Node.js application called app.js via SSH

I am attempting to establish an SSH connection to two servers sequentially in order to execute the following command: sudo node app.js This is the code I am using: #!/bin/bash while read line; do ssh -i "sshtest.pem" ec2-user@$line "sudo node app. ...

Tips for nesting ng-repeat with two connected entities

I am working with two entities: OrderOpened ProductOrdered which has a ManyToOne relation with: relationship ManyToOne { ProductOrdered {Order} to OrderOpened } My goal is to display Orders along with their related Products in a single view. Displ ...

Using ajax to send a JSON object to a controller class in a Spring MVC application

I have recently delved into learning spring mvc and decided to practice on my own. However, I encountered an error that has left me puzzled. Can someone please help with the code? When passing a JSON object from my JSP page to the controller class, I rece ...

Trouble with concealing the headers of a table in AngularJs

I am currently working on developing an angular application that displays football scores. Users can select the option for 2015 matches and only view information for games played in that year. However, I'm facing an issue where even when the 2015 chec ...

Group MongoDB Arrays by Date using Aggregation

Here is a data set consisting of two object arrays: _id:"PBea1d7ca5-5865-493b-bf05-40a9665de00a" checkouts:Array 0:Object date:2018-11-23 17:29:49.483 id:"CICOf3195baf-49b4-484e-ab39-03ab1f79ca04" waitlist:Array 0:Object da ...

Ways to utilize gulp-rigger

When I include a .coffee file in a .js file, the gulp-rigger compiles it "on the fly" and concatenates it. Is there a way to pass parameters like { bare : true }? It seems to only work with default settings. Does anyone have experience using this plugin ...

Capturing the Facebook Login Event to dynamically modify the content of the main webpage

My current project involves creating a Facebook-based login system using JavaScript. When a user clicks a button, I want one div to be replaced by another if the user is already logged in to Facebook. If they are not logged in, I prompt them to enter their ...

Building on Angular service hierarchy with Object.create()

Exploring the concept of inheritance in Angular services is my current objective. I came across this helpful resource: . I am particularly interested in implementing the "Inject the parent" technique. However, despite following the guidelines, I'm fa ...

Modifying URLs with backbone.js

When it comes to my Backbone module, I typically access it via the URL: http://localhost/src/index.html#test_module However, there is another module that I need to view which can be accessed using the URL: http://localhost/src/index.html#test_module ...

Achieve this effect by making sure that when a user scrolls on their browser, 50% of the content is entered into view and the remaining 50%

Is there a way to achieve this effect? Specifically, when the user scrolls in the browser, 50% of the content is displayed at the top and the other 50% is shown at the bottom. ...

Searching for the element that triggered the event using jQuery or JavaScript

Can anyone offer tips on how to use console.log to identify the element that triggered a hover event? I'm trying to debug an issue specifically on iOS. I'm not looking to locate the specific item that the action was performed on, but rather what ...

perform loading of dynamic JSON data in Grunt

Can a JSON file be loaded from a dynamic source for localisation purposes? grunt.file.readJSON('src/locales/<%= grunt.task.current.args[0] %>/i18n.json'); A sample section of the Gruntfile is as follows: module.exports = function(grunt) ...

Javascript regular expression fails to find a match

Is there a way to match all strings except for the ones containing '1AB'? I attempted it but it returned no matches. var text = "match1ABmatch match2ABmatch match3ABmatch"; var matches = text.match(/match(?!1AB)match/g); console.log(matches[0]+" ...

What is the process for converting Database/Table Data into a File Name?

Hey there! I have a query regarding Leaflet Markers that I need help with. So, I have this database table with a field named icon_name which contains values like: |icon_name| ___________ |FIRE | |HOMICIDE | |RAINSTORM| Additionally, I have a folder ...

Learn the technique for showcasing numerous markers on Google Maps, each equipped with its own individualized info windows

https://i.sstatic.net/1tTUD.png // map center var center = new google.maps.LatLng(2.855262784366583, 105.4302978515625); function initialize() { var mapOptions = { center: center, zoom: 7, mapTypeId: google.maps.MapTypeId.ROADMAP }; // Create a < ...