API Project: URL Shortener Microservice for freeCodeCamp- MongoDB

So i cant figure why my code isnt working.

app.get("/api/shorturl/new/:url(*)", function(req, res) {
  var url = req.params.url;
  var resultArray = [];

  //is the url a valid one?
  if (validUrl.isUri(url)) {
    //if the url is valid
    (async function() {
      //new mongo client
      const client = new MongoClient(dburi, {
        useNewUrlParser: true,
        useUnifiedTopology: true
      });
      try {
        //connect to mongodb
        await client.connect();
        console.log("Connected correctly to server");
        //select database
        const db = client.db(dbname);
        // select collection
        const col = db.collection(dbcURl);

        //check if there is a url in the database
        var cursor = col.find({ url: url });

        // Iterate over the cursor
        while (await cursor.hasNext()) {
          const doc = await cursor.next();
          //save doc in array
          resultArray.push(doc);
        }
        //if result array < 1 then there are not any urls matching in the data base
        if (resultArray.length < 1) {
          var amount = 0; //amount of urls in db
          //url needs to be added to the database
          //get amount urls to hash
          var docs = await col.estimatedDocumentCount(function(err, res) {
            assert.equal(null, err); //check for errors
            amount = res;
          });

          // mongo db schema
          var URLitemBody = {
            url: url,
            hash: amount + 1
          };
          //insert new schema
          docs = await col.insertOne(URLitemBody, function(err, res) {
            assert.equal(null, err); //check for errors
          });
        } else {
          //else means that there are at least one url matching in the data base
          //find the url
          var amout;
          var docs = await col.estimatedDocumentCount(function(err, res) {
            assert.equal(null, err); //check for errors
            amount = res;
          });
          
          docs = await col.find().map((doc, err) => {
            assert.equal(null, err);
            resultArray.push(doc);
          });
          //response json
          res.json({ original_url: url, short_url: amount });
        }
      } catch (err) {
        console.log(err.stack);
      }

      // Close connection
      client.close();
    });
  } else {
    console.log("not a valid URL");
    res.json({ error: "invalid URL" });
  }
});

im following the gidelines of CRUD operations

here its the glitch project if anyone wants to see the full source code

what im doing wrong?

Hii there!

Your entire code (Storing shortened URL & Retrieving shortened URL) is within one GET call.
You need to split ‘Storing shortened URL’ part into POST (also check the URL correctness using DNS lookup) and ‘Retrieving shortened URL’ part into GET.

Hope this helps