Database creation

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,

please give more details:

  • where is your database server, Atlas?
  • what language is your backend app uses, javascript?
  • does other endpoints work?
    • here you seem to add a new review, what about other create operations?
    • your error seems to be a read query, do other read endpoints work?
    • is this error is on read-all or read-one?
  • have you tried putting log lines in endpoints? “println”, “writeline”, “console.log”?

Okay,good day sir, u asked me for my database server atlas, so I will provide u with a picture of what I think might be the answer


2. You adked me for which app is my backend app using, okay thats index.js, so it’s javascript I am using

  1. 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 :thinking: 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

I have found a matching repl to yours: review-backend - Replit

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

this link, for example, runs the repl I linked and returns few reviews for a movie of id 1: https://review-backend.beaucarnes.repl.co/api/v1/reviews/movie/1

and this one is yours, with results: https://review-backend.dglory1.repl.co/api/v1/reviews/movie/12

Sorry sir pls it didn’t work that api/v1/reviews/movies/12
It just said-> {“error”: “not found”}
It didn’t create any database on mongodb

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.

I suggest taking the following course. It is free and provided by MongoDB.

MongoDB Node.js Developer Learning Path | MongoDB University

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.

The repli is mine the dglory account is my repli I created the password and username for it so it is mine, its not someone own I am using

I will provide u with my repli address soon my system is down now

Alright then, I checked your list of repls and this one seems your frontend.
htmlfrontend - Dglory1 - Replit

Then, these are the main problems:

  • you define a variable to your backend repl, but you are not using that variable at all. your code tries to connect to “themoviedb”
  • your code is like a maze, thus you are using the wrong variables names in some parts
    • a refactoring would be nice: for example move html changing parts to their own functions.
1 Like

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

Here, check this code (click the arrow)

Code to show a review list
const url = new URL(location.href);
const movieId = url.searchParams.get("id")
const movieTitle = url.searchParams.get("title")

const APILINK = "https://review-backend.dglory1.repl.co/api/v1/reviews/";

document.addEventListener('DOMContentLoaded', returnReviews )

function returnReviews() {
  fetch(APILINK + "movie/" + movieId)
    .then((res) => res.json())
    .then((data) => {
      console.log(data);
      const main = document.getElementById("section");
      data.forEach((review) => {
        const div_card = document.createElement("div");
        div_card.innerHTML = `
            <div id="${review._id}">
              <p>
              <strong>Review: </strong>${review.review}
              <strong>User: </strong>${review.user}
            </div>`
        main.appendChild(div_card);
      });
    });
}```

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.

Okay thanks I will try that out

This topic was automatically closed after 180 days. New replies are no longer allowed.