bradtraversy / nodekb

Simple knowledgebase app with Node.js, Express and MongoDB
304 stars 185 forks source link

"TypeError: Cannot read property '_id' of undefined" #12

Open Alpgul02 opened 4 years ago

Alpgul02 commented 4 years ago
.
.
.
 let article = new Article();
    article.title = req.body.title;
    article.author = req.user._id;
    article.body = req.body.body;
.
.
.

Here in router.post('/add',....

I get the error of "TypeError: Cannot read property '_id' of undefined".

But I can correctly login with user.

How to solve this?

techyharshit123 commented 3 years ago

_id is not a property defined by you. It is by default assigned to every entry. So it's not property but it's a key and can't be accessed like this.