Tell us what’s happening:
I cannot seem to get the url shortener to increment. I’m running it as a while loop, where it checks if there is a record with short_url: i(starts at 0), if there isn’t, it puts this record there. if there is, it increments the i variable and tests again, basically putting them in sequentially.
This is not how it is happening though. I’ll attach 2 excerpts from my code as well as the repl.
Your code so far
definition of functions
console.log(number)
await URL.findOne({short_url: number}, (err, user)=>{
if (err){
return 'err'
}
if(user){
return true;
}else{
return false;
}
});
}
within the post request
```
let i = 0
let hasurl = true
while(hasurl === true){
console.log('incrememnting')
//is there a record of this number?
hasurl = findByAsync(i)
i++
}
//Then assign that number to the URL by creating a new record with the url and the number
//this is supposed to make the url in database and save it with a number, currently not working? do i put done in?
createAndSaveUrl(req.body.url,i)
repl link: https://repl.it/@SethAlan/boilerplate-project-urlshortener#server.js
**Your browser information:**
User Agent is: <code>Mozilla/5.0 (Macintosh; Intel Mac OS X 11_1_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36</code>.
**Challenge:** URL Shortener Microservice
**Link to the challenge:**
https://www.freecodecamp.org/learn/apis-and-microservices/apis-and-microservices-projects/url-shortener-microservice