Why not show full json object in monogodb compass?

//todo post
router.post('/', async  (req, res) => {
  const newTodo = new Todo(req.body);
  const result = await newTodo.save(err =>{
    if(err){
        res.status(500).json({error:'there server site error'})
    }else{
        res.status(200).json({message:'todo successfully inserted'})
    }
  })

res.send(result);
})

//test postman object
{
    "title":"rayhan 1",
    "descreption":"mern learning",
    "status":"active"
}

//mongodb compass result 
id:ObjectId('64660fd712cad04ad873d5c5')

__v:0

//why not show full  json object ?????

//terminal error 
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client

I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

likly i chage it same result …

router.post('/', async  (req, res) => {
  const newTodo = new Todo(req.body);
  await newTodo.save(err =>{
    if(err){
        res.status(500).json({error:'there server site error'})
    }else{
        res.status(200).json({message:'todo successfully inserted'})
    }
  })


})

Is req.body empty? Have you added a body parser middleware?


Please post a repo with the code so we can see all of it.


Use the “preformatted text” tool in the editor (</>) to add backticks around the code.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.