0

I'm not sure why i'm having this weird error. I'm using route.put and selected PUT on my post man.

Here's my post man error: Image link->https://ibb.co/dzvAKc

All of my musics on my mongoDB data: Image link->https://ibb.co/d9TY5H

Routes:

const User = require('../models/user');
const Music = require('../models/music');
const jwt = require('jsonwebtoken');
const config = require('../config/database.js');
module.exports = (router) => {

Update function:

router.put('/updateMusic', (req, res) => {
    if (!req.body._id) {
        res.json({ success: false, message: 'No music id provided.'});
    }
    else { .. more authentications here }

return router;
};

Somehow it can't get pass that 1st if.

[UPDATE] :

Here's the img for the headers-> https://ibb.co/mGr9vH

Vlael
  • 32
  • 1
  • 7
  • can you check this post to see if your problem is not related ? https://stackoverflow.com/questions/42128238/how-can-i-read-the-data-received-in-application-x-www-form-urlencoded-format-on . Thx – Pierre Mallet Mar 20 '18 at 12:46
  • i already use body-parse, also my registration form is already running, and can also retrieve the data on my edit form. i'm not really sure why seems can't i get the id. – Vlael Mar 20 '18 at 12:54

2 Answers2

0

It seems your have a typo here :

router.put('/updateMusic', (req, res) => {
    // if (!req.body._id) { <-- HERE _id, but it seems its id 
    if (!req.body.id)
        res.json({ success: false, message: 'No music id provided.'});
    }
    else { .. more authentications here }

return router;
};
Pierre Mallet
  • 7,053
  • 2
  • 19
  • 30
0

Replace req.body._id with req.body.id Also - do you have app.use(bodyParser.urlencoded({ extended: true })); ? You are sending request with Content-Type application/x-www-form-urlencoded, so this line will parse this and assign data to body property

hejkerooo
  • 709
  • 2
  • 7
  • 20