async-labs / builderbook

Open source web application to learn JS stack: React, Material-UI, Next.js, Node.js, Express.js, Mongoose, MongoDB database.
https://builderbook.org
MIT License
3.77k stars 892 forks source link

Unhandled Rejection (TypeError): Cannot read property 'email' of null #203

Closed ghost closed 3 years ago

ghost commented 5 years ago

Hello,

I am in the middle of Chapter 2 and just created my document on MongoDB Atlas. Following the instructions I am getting the error "Unhandled Rejection (TypeError): Cannot read property 'email' of null" when trying the get the email from the database.

Any ideas what has gone wrong?

Thanks. Andy


Click to see Hill for issue #203
  <div><img src="https://async-github-hills.s3.amazonaws.com/builderbook-builderbook/203.png" alt="Single issue hill" class="s3-image" width="100%" /></div></details>
  <details><summary>Click to see <b>Hill for all issues </b></summary><div>
  <img src="https://async-github-hills.s3.amazonaws.com/builderbook-builderbook/all-issue-hill.png" alt="All issue hill" class="s3-image" width="100%" /></div></details>

created by Async

tima101 commented 5 years ago

@tungandy Did you find a problem?

igigi commented 5 years ago

I have the same problem.

mrhanson3 commented 4 years ago

I'm having that issue now.

elysenko commented 3 years ago

Did anyone find a solution to this? I'm getting the same problem

klyburke commented 3 years ago

@elysenko thanks for noting. I will try to reproduce the problem or then explain or solve the issue.

klyburke commented 3 years ago

@elysenko I ran the 2-end codebase and was able to retrieve email address from my database.

Can you try running the 2-end codebase? Do you get the same error?

If you don't get an error when running 2-end, then there's probably an issue in the codebase you are running as you work through Chapter 2.

If you still get an error when running 2-end, then there's probably a problem in the connection to your database.

elysenko commented 3 years ago

When I run the 2-end code I get the same error... In checking the connection to my db, I confirmed that running yarn dev-express does create a users collection in my db, so maybe that rules out a connection issue?

klyburke commented 3 years ago

@elysenko thanks for testing.

Could you create a public repo with the exact code that is giving you an error? We will run the code and look for the problem.

klyburke commented 3 years ago

@elysenko did you figure out the problem?

elysenko commented 3 years ago

not yet. https://github.com/elysenko/2-begin

klyburke commented 3 years ago

Thanks, I will test and see if I can reproduce the problem.

elysenko commented 3 years ago

@klyburke any word?

klyburke commented 3 years ago

@elysenko I ran your code with my own .env file and did not have a problem. The app loaded as expected with the email address from my database.

There are a few potential problems you can check:

(1) Does your MONGO_URL have the correct name of your database? Recall that MONGO_URL has the following format mongodb+srv://<username>:<password>@cluster0-eoobe.mongodb.net/<db>?retryWrites=true

db is the name of your database. I found that if this name is incorrect, you will see TypeError: Cannot read property 'email' of null.

(2) It's possible that MongoDB Atlas is not properly connecting to your IP address. Atlas has a troubleshooting guide: https://docs.atlas.mongodb.com/troubleshoot-connection/

(3) You may have an error in the user document you created. Check that your document has these fields with the proper type (e.g. Date, String): image

elysenko commented 3 years ago

Alright. My issue was the document created on the db. The textbook doesn't have you create it until after you run yarn dev-express. You get the error when there is no document created. Thanks for your help!