Pls I am having issues creating my database in mongodb,I am using replit IDE, no errors in my “console”, “Shell”, my codes are working fine, it said succes when I tried using curl link to create my database in “Shell” so I dont know what is wrong I tried using schema code for linking stuff didn’t work even mongodb compass, isnt working tried configuring open ssh server to see if the issue would be resolved still didn’t work, I have tried soo many things that I am speechless self on what to do
I would have uploaded the others but this one explains it more, what I meant, and also I wanted to upload them but i cant because I am a new user, new users can’t upload more than 1 media, I am not because this is my first time visiting mongodb with my phone, I use my laptop mostly for that to visit mongodb,
2. You adked me for which app is my backend app using, okay thats index.js, so it’s javascript I am using
You asked me for endpoints:
I) I don’t understand where u said what about create operations? Is there anyway I can do that with examples, this is my first time hearing that
II)You were asking if other read endpoints work, so okay if u meant my api url, yeah it is working I checked that out the website I am creating using javascript, css and html is working is just this when I tried creating database with mongodb using a different javascript folder I created that the issue came from
III) U asked me if other read endpoints work like i said before there’s no error everything is working fine, I created two folders, one for the first work then this I am is the second work, the 1st work is the website I built, this one is currently on mongodb
4 You asked me if have tried putting logs in endpoints, like console.log e.t.c do u mean in the api url, if u meant so or u didn’t pls can u provide me with examples?
Thanks so much for providing feedback to my 1st question, sorry for the long note I typed just I just wanted to explain in details and if that’s what u meant
from the looks, I would say you have not provided a movie id in your url. when you used “curl” you have inserted a movie with an id of 12. so your url should end with “…/api/v1/reviews/movie/12” to get reviews for the movie.
there are few issues with it:
an new empty database return nothing, and you get “not found”.
you need to first add a review with movie id.
you get “not found” if you don’t give an id in the url, either for movie or review.
more importantly, that repl has a couple of design issues on defining endpoints. for example, it loads all reviews at the beginning without a filter, so take it as an example only.
now about endpoints. since you are new, here is a quick intro. it is CRUD meaning Create-Read-Update-Delete, and endpoints are the names and methods. for example for a movies database
/api/v1/movies + POST method : create a new movie
/api/v1/movies + GET method : get list of all movies
/api/v1/movies/123 + POST/PUT/PATCH method : update movie 123 (method name is one to argue)
/api/v1/movies/123 + DELETE method : delete movie 123
Sir pls for the last post u sent about a brief intro to endpoints can I use that I typed from the https to the post method for the no 1 it was displaying errors
this endpoint is reading all reviews for a given movie with an id.
check the “server.js” file. app.use("/api/v1/reviews", reviews) tells you that to operate on reviews your url must have this form .../api/v1/reviews/.... then in “api/reviews.route.js” file you see the rest of the endpoints to append to this url:
.../api/v1/reviews/movie/12 + GET method is to get all reviews for movie of id 12 (12 is just an example)
.../api/v1/reviews/new + POST method is to create a new review
.../api/v1/reviews/123abc + GET/PUT/DELETE methods are to read/update/delete the review with id of 123abc. this id is just an example. an actual mongodb id corresponds to a 12 or 24 character string.
so your frontend must communicate with this backend server through these endpoints. check “api/reviews.controller.js” to see how requests are processed. when using POST you need to send an object in the request body similar to the one you used with curl in your first screenshot (req.body.movieId, req.body.user, req.body.review). GET and delete needs only an id in the url (req.params.id). PUT needs both an id in the url and object in the body.
by the way, this server is open to public as you can see, and anyone can read/write/delete on these endpoints right now. so when you finish learning basics, you may want to learn security basics after.
Okay that means u were saying that there is something wrong with my server.js or something that I am not able to create a database?
Is there anything I can do to resolve it? My system is down so I have to charge it when I buy light, but still then is there anything I can do in order to resolve it?
But sir is there anything wrong with my codes so far, I have cross-checked soo many times still no errors, like I am confused on what to do, is there anyway I can connect with that man beaucamps?
are you the owner of dglory1 account? else can you give your repl’s address?
except design flaws, there is nothing wrong with both repls I linked. the problem is your expectation it seems.
these repls are coded only to create a review with a movie id, get reviews for that movie, and 3 more operations on a single review, that is all. you cannot do anything else. you need to crawl the source code, learn how endpoints work, adapt/expand the source so you can do more.
you don’t have to follow that source alone. there are many resources to write your own backend server with different purposes. there are many “To do” application examples also with their frontend applications. MERN stack for example, use Express.js (as these repls do) for backend and React.js for frontend.
Good day sir I watched the videos on how to create a database using mongodb, so my issues is that the review isn’t created in my website, for people to post review about a particular movie
You did not answer that part, but you do not seem so. I am guessing you were using someone else’s repl all these times because your first screenshot shows the successful creation of a review. you cannot create something on your database using a url that does not belong to you.
Okay I understood what u were saying when u talked about I using the wrong variables, u also said I should refactoring my code, how will I move html changing parts to their function pls is there an example
Use this instead of your current “movie.js” and your reviews will show up in the page, proving your backend is already working.
you just need to learn more about
connecting a backend server to database server
writing endpoints in your backend to read data from frontend
connecting your frontend to a backend
processing the data you read from backend and connecting to your user-facing parts, namely html
for all these steps, there are countless resources on the internet, however, they are not always in one place. And not all resources might be suitable for your learning pace.
I will make an exception and suggest “Dave Gray” from youtube ( DaveGrayTeachesCode) for things including HTML, CSS, Javascript and MongoDB.
you can move to any other resource at any time if his style is not for you.