Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Alpgul02 opened this issue Jun 3, 2020 · 1 comment
Open

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

Alpgul02 opened this issue Jun 3, 2020 · 1 comment

Comments

@Alpgul02
Copy link

Alpgul02 commented Jun 3, 2020

.
.
.
 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
Copy link

_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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants