K
K
Kentavr162021-06-19 19:58:47
Mongoose
Kentavr16, 2021-06-19 19:58:47

How to parse object returned from mongoose?

mongoose from the back, upon request to find a user, returns an object of type [{_id:"12312313", FirstName:"dfdfdf", etc.}]. How to parse this object? Can't get regular valid json. I would be very grateful for a nod in which direction to dig.
p.c. - on the back also tried to convert - with the same zero result.
server route:

router.post('/loginUser',async function(req, res){
    try{
    const UserF = await User.find({"Password":(req.body.Password)})
    res.json(UserF)
    console.log(UserF)
} catch(err){console.log(err)}
}
)


and client
handleSubmit(e){
  e.preventDefault();
  var CandidateUser = this.state
  axios.post('/api/loginUser',(
 CandidateUser
  ))
  .then(res=>{console.log(res.data)
  })
  .catch(err=>{alert(err)})
}

as a result comes

[
  {
    _id: 60cdc1bb3ac3651ed0915a46,
    FirstName: '.имя',
    LastName: 'фамилия',
    Created: '19.06.2021, 13:06:50',
    Password: '11111111',
    __v: 0
  }
]

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question