Troubleshooting: Angular2 and Mongoose update issue

I am currently facing a challenge with updating MongoDB using Mongoose. Although there are no error messages, the update process is not taking place even after trying various solutions.

exports.update_a_keyValue = function(req, res) {
    console.log("templatecontroller: update_a_template - templateID:", 
    req.params._id, req.body);
    Template.findOneAndUpdate({_id: req.body._id}, req.body, {new: false}, 
    function(err, keyvalue) {
    if (err)
       res.send(err);
       res.json(keyvalue);
   });
 };

In the Express window, I see that there are no errors being returned. However, on the network side, I am encountering 204 and 304 errors.

templatecontroller: update_a_template - templateID: 
 5a1c22ab8af22e408c9bd0f4 
{ _
id: '5a1c22ab8af22e408c9bd0f4',
 key: 'testingthisagain',
__v: 0,
  values: [ { value: 'tesddfdfdf' }, { value: 'testingthisagain1' } ] }

Answer №1

Your coding solution is accurate.

By setting {new: true}, the updated document will be returned; if set to false, it returns the document prior to the update.

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

Issue with Laravel Spark due to NPM Dependencies

Trying to install Spark within Laravel on a Docker container running Debian 8, but encountering an error when running NPM update. Not sure how to resolve this issue. Installing NPM Dependencies... npm WARN deprecated <a href="/cdn-cgi/ ...

Developing middleware for managing event handlers

Scenario: I am tasked with managing multiple events that necessitate an "available client". Therefore, in each event handler, my first step is to attempt to acquire an available client. If no client is available, I will send a "Service unavailable" messag ...

Launching a Phonegap app using Node.js and Express framework

My goal is to transform my current webapp into a mobile app. The existing setup consists of a nodejs-express REST API server with an HTML/JS client. I aim to utilize the API from the REST server and replace the client with a phonegap/cordova based mobile ...

Using node.js to download files with axios, streaming the content, and then

I am attempting to download a PDF file using axios, and save it on the server side using fs.writeFile. My code is as follows: axios.get('https://xxx/my.pdf', {responseType: 'blob'}).then(response => { fs.writeFile('/temp/my ...

Webpack encountering issues with @font-face declaration

I'm encountering a problem with Webpack and FontAwesome. These are the loaders I am using: module: { loaders: [ { test: /(\.js$)|(\.jsx$)/, exclude: /node_modules/, loader: 'babel-loader' }, { test: /(\.ja ...

The specified public directory could not be located

I'm trying to utilize Node.js with Express, and I recently found out about being able to specify a 'public' directory for serving static files. I've been attempting to place my bootstrap css/js files in the public directory, but I keep ...

What is the term used for the objects that res.render passes?

I constantly find myself struggling with defining objects inside res.render. Is there a way to define them globally or outside of res.render? I hope someone can offer some guidance.. here is a sample code snippet: router.get("/home/blog", function(req,r ...

Searching for MongoDB / Mongoose - Using FindOneById with specific conditions to match the value of an array inside an object nestled within another array

Although the title of this question may be lengthy, I trust you grasp my meaning with an example. This represents my MongoDB structure: { "_id":{ "$oid":"62408e6bec1c0f7a413c093a" }, "visitors":[ { "firstSource":"12 ...

Transforming timestamps to month day, year format and back again without the use of any NPM packages

I have developed a microservice that converts Unix timestamps to a format like Dec 01, 2017 and vice versa. The microservice is deployed at this link: timestamp I am wondering if there is a better way to achieve this without using third-party NPM modules. ...

Can templates be nested within other templates using different contexts?

I am in the process of developing an application using nodejs and handlebars. My goal is to create a layout template and insert various individual components into that layout. Each component will have its own handlebars template and context. e.g. layout. ...

Error 302 encountered during testing of Stripe webhook functionality

Testing a stripe webhook for subscription trial ending is proving to be challenging. Every time I attempt to send the test event to my webhook receiving route, I encounter error 302. Utilizing a middleware known as stripe-webhook-middleware, my defined rou ...

Execute unit tests for the nodejs project

Looking to execute the tests for this project on GitHub? Head over to the test folder on https://github.com/node-opcua/node-opcua. However, I'm unsure about the testing framework that was utilized and how to run all the tests. Any guidance would be mu ...

Encountering the following error message: "MongoServerError - E11000 duplicate key error on collection: test.users, index: email_1. Duplicate key found: {email: null}"

I'm a student working on creating a login authentication API using Node, Express, and MongoDB. My issue is that I can't add multiple users when signing up. Despite searching through numerous threads on this website, I haven't found a solutio ...

Node.js: Deciding between res.render and res.redirect in express-session

On my website, I have a login page and a myservices page. Once a user logs in, they should be redirected to the myservices page where their username is displayed. In the login.js file, the following code is used: req.session.user = "abc"; res.redirect(&a ...

Running an executable file from a remote machine on my local machine using node.js

As we develop our application using node.js and electron, we encounter a situation where another software is already installed on all other machines. Now, the question arises: Can we launch this software from within our node.js application on these respe ...

Unable to transfer images from the frontend to the backend

I am having trouble sending a group of images from my input to the backend. I keep receiving them as undefined or empty []. Can anyone provide guidance on how to resolve this issue? I am currently using nextjs 14. The images are defined and visible in th ...

What is preventing me from defining an alias @bundled-es-modules/chai for chai?

When working with NPM, you have the option to install a package under an alias, like this: npm i alias@npm:real-package-name To learn more about this aliasing feature, check out the announcement here: b7b54f2d1 413 #3 530 Add support for package aliase ...

The React client is unable to establish a connection with the server socket

Recently diving into the world of socket-io and react, utilizing express for the backend. The socket.io-client version being used is 3.0.3, while the backend's socket-io package matches at 3.0.3 as well. Interestingly enough, the server handles connec ...

Trouble with Array data being saved as empty in MongoDB database after sending Axios post request from

My Schema looks like this (with some options omitted for simplicity): const SubmitDebtSchema = new Schema ({ balance: [{ balanceDate: Date, newBalance: Number }] }); This serverless function posts the Schema to my database: module.exports = as ...

Manipulating arrays in a JSON file with JavaScript

Struggling with adding a new value to an array stored in a file.json? The array currently contains ["number1", "number2"], and you want to add "number3". However, attempts to define a variable in the JavaScript file containi ...