Joey
Joey

Reputation: 1

getting undefined while accessing object properties in nodejs in mongodb

I'm building webapp using node and mongodb where i'm registering userdata in one api and getting jwt token as response and passing that token in another api and retrieving user data while doing that i'm able to get json object as response but .I'm getting undefined while i try to access one of the json object using . notation my response is printing like this

req.user is printing Object like below

{ "user": { "_id": "5f0082efe997800c40115be1", "name": "John Max", "email": "[email protected]" }, "iat": 1593869039 }

req.user._id gives undefined i tried accessing like this req.user[_id] as well nothing works ! where req.user is of type of object

Upvotes: 0

Views: 196

Answers (1)

jinwar
jinwar

Reputation: 386

without a clue on the code you used I'm probably wrong but :

  • If when you log "req.user" you get { "user": { "_id": "5f0082efe997800c40115be1", "name": "John Max", "email": "[email protected]" }, "iat": 1593869039 }, then you should access _id with : req.user.user._id (if I never saw this before I would'nt allow myself to suggest that ...)

  • Maybe it's an issue about parsing the json ?

Upvotes: 1

Related Questions