DEV Community

ivkeMilioner
ivkeMilioner

Posted on • Updated on

Anbody working with MERN? I have error.

I have a problem with reading data from mongo. I can't find the problem. I get an empty array from mongo.

https://github.com/dragoslavIvkovic/MERN-WOLT/tree/master

Top comments (12)

Collapse
 
dawnind profile image
Mainak Das • Edited

Elaborate ?
Add help as tag also

Collapse
 
ivkemilioner profile image
ivkeMilioner

That is problem. I can't find where is problem. I getiing empty array from mongo database. In this file I geting only "Loading"
github.com/dragoslavIvkovic/MERN-W...

Collapse
 
dawnind profile image
Mainak Das

I tried to git clone the repo and starting to debug but found mongo connect error/ timeout? Will that be the problem? I'm guessing not. Can you remove the IP restrictions (if any) so that I can debug further? :D

Thread Thread
 
ivkemilioner profile image
ivkeMilioner

I removed IP restriction

Thread Thread
 
dawnind profile image
Mainak Das

I checked the logs, the thing you were doing was not connecting the DB to the running server. As a result DB is running its own and server in its own. Second thing you need to add CORS to enable API access from other domains.

Tried to push the updated code, but blocked.

Thread Thread
 
ivkemilioner profile image
ivkeMilioner

Thank you to heaven for spanindg your time on me. Thank you to heaven for wasting your time on me. Can you email me an update?

Thread Thread
 
dawnind profile image
Mainak Das • Edited

No worries man ;) debugging is always good
Also I checked your DB, there are two tables food and foods. The Food.find({}) is accessing the food table. You may have to check that to get the required values from the correct table i.e foods.

Can you ping me at mainakdas104@gmail.com 😊

Thread Thread
 
ivkemilioner profile image
ivkeMilioner

I sended invite

 
ivkemilioner profile image
ivkeMilioner
Collapse
 
davidfree2 profile image
Humberto David Esquerra

My advice would be to checkout w3schools use of mondgodb. They don't use mongoose they use the official mongodb npm driver. Also try to keep everything in your database.js file and add function arguments to fetch specific collection documents by name. My last advice would be make sure the data your sending to client is a resolved promise. If it isn't a resolved promise your gonna need another call back to resolve the data in the frontend. Good luck! Hang in there!

Collapse
 
jlong4223 profile image
Jared Long

What’s getting logged from the console log in your ‘foodAction.js’?

Collapse
 
jlong4223 profile image
Jared Long • Edited

It could potentially be related to your action dispatching GET_FOODS_REQUEST, which sets loading to true but that dispatch doesn’t contain any new state. I wonder if your try/catch is being ran