project_mern_memories icon indicating copy to clipboard operation
project_mern_memories copied to clipboard

Posts from the database won't load, but I can create a new one just fine.

Open ghost opened this issue 3 years ago • 5 comments

I have an issue where my posts from the database won't load but if I create a new post, the new one's will show up just fine. If I then refresh the page, the posts disappear again and I just get my loading screen. Any new posts are sent to my database with no issue, so I know my DB connection is OK. I started getting status code 404 whenever I reload the page. Anybody else facing something similar? Any idea how to fix it?

ghost avatar Oct 12 '21 16:10 ghost

@benitoito Check out your mongo DB schema first and your upload, download, mongo DB actual data as well. If mongo DB's data all set up correctly in a mongo DB cloud it maybe a problem with getting data from a server.

mauvpark avatar Oct 15 '21 05:10 mauvpark

I'm having a similar issue, if anybody solves it let me know @benitoito

hafeed06 avatar Oct 15 '21 17:10 hafeed06

Solved for me! Actually it was just a silly mistake. in App.js in the useEffect hook, I wrote: dispatch(getPosts); instead of dispatch(getPosts());

Reviewed the first tutorial until I saw it, I hope it's the same thing for you!

hafeed06 avatar Oct 16 '21 21:10 hafeed06

I also had same issue. Fixed by adding the ! in !posts.length in the posts component. then they displayed.

imjord avatar Mar 16 '22 19:03 imjord

I am facing the same issue even when doing what you both did @hafeed06 and @imjord. I can see that the post does get created in my MongoDB cluster but doesn't seem to be retrieved on the front end. Any ideas what the issue might be?

Update: I solved the issue by making sure the useEffect(() function is under const dispatch = useDispatch();

outterspacem avatar Dec 28 '22 23:12 outterspacem