URL Shortener Microservice - MONGODB problems

Hi guys,

I have a problem with URL Shortener Microservice Project. I am struggling with MongoDB I guess. I am not even sure if my connection is working. I’ve spent whole weekend with this but my API always freezes or shows nothing.
I have no idea how to correctly work with MongoDB, they changed the connection string syntax now and some other stuff. (https://www.mongodb.com/blog/post/mongodb-3-6-here-to-SRV-you-with-easier-replica-set-connections)
So please if somone can give me some advice where to look and how to understand this mongodb concept

I will be very thankful guys

Your code so far

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36.

Link to the challenge:

yea there is the string

MONGO_DB=mongodb://lauf_martin:<password>@cluster0-w77st.mongodb.net/test?retryWrites=true

atlasmongo gave me this but it didnt work

mongodb+srv://lauf_martin:<password>@cluster0-w77st.mongodb.net/test?retryWrites=true&w=majority

Thanks for any help

I changed it as you recommended but it’s still not working unfortunately. When I press POST URL button, response is correct only regarding URL validity (regex & dns check) but find in DB is obviously not working.

Then I tried to change the dependencies but it stopped working completely…so I am not sure what to do, start once again from the beginning?

Hi, after dependencies change it thrown:
WARNING: The useMongoClient option is no longer necessary in mongoose 5.x, please remove it.

and error was:
TypeError: connection.model is not a function

I tried to change autoIncrement plugin as you suggested but result was the same

It looks like I need to start from the scratch :frowning:

thank you very mich for all the effort. I left it like before and there is no error in log now. You can edit as well:

I guess it’s doing something…I can monitor some activity on my cluster

image

that is strage it should I generated inside glitch. Is it only one shot link?

This is another one

I used this feature of glitch to create previous link

image

there is the link you mentioned above

I was using just mongodb so I added srv
and then update dependencies

    "mongodb": "^3.2.6",
    "mongoose": "^5.6.4",

But I see error like this now:


TypeError: connection.model is not a function

at Object.exports.initialize (/rbd/pnpm-volume/3231a0e3-c114-42cd-8803-7a554bc5bc70/node_modules/.registry.npmjs.org/mongoose-auto-increment/5.0.1/node_modules/mongoose-auto-increment/index.js:10:34)

I did everything you mentioned above but that is what I got

/rbd/pnpm-volume/3231a0e3-c114-42cd-8803-7a554bc5bc70/node_modules/.registry.npmjs.org/mongoose-auto-increment/5.0.1/node_modules/mongoose-auto-increment/index.js:27

8:03 PM

throw ex;

8:03 PM

^

8:03 PM

8:03 PM

TypeError: connection.model is not a function

8:03 PM

at Object.exports.initialize (/rbd/pnpm-volume/3231a0e3-c114-42cd-8803-7a554bc5bc70/node_modules/.registry.npmjs.org/mongoose-auto-increment/5.0.1/node_modules/mongoose-auto-increment/index.js:10:34)

8:03 PM

Jump Toat Object. (/app/server.js:22:15)

8:03 PM

at Module._compile (module.js:653:30)

8:03 PM

at Object.Module._extensions…js (module.js:664:10)

8:03 PM

at Module.load (module.js:566:32)

8:03 PM

at tryModuleLoad (module.js:506:12)

8:03 PM

at Function.Module._load (module.js:498:3)

8:03 PM

at Function.Module.runMain (module.js:694:10)

8:03 PM

at startup (bootstrap_node.js:204:16)

8:03 PM

at bootstrap_node.js:625:3

8:03 PM

2 minutes ago

I copied content of server.js and package.json to my project but I still have same error. That must be my connection string otherwise I really dont understand.

Hi, it was really messy all those versions and compatibilities so I started new one. Finally , I was able to make it work

app: https://surf-macaroon.glitch.me/
code: https://glitch.com/edit/#!/surf-macaroon

I decided to skip auto-increment plugin and instead of it I ran find function without argument so I could count all records in DB. In case of new posted url, new short url will be count + 1. I tried to generate shorturls randomly but it seemed like not very good approach.

To be honest it was a lot of struggling, me and many other campers would be grateful to have more learning content than just a few challenges. It’s really challenging especially from the beginning of new topic.

For example content like this:


helped me finish D3 visualization quite easily after I watched it.

Anyway thanks for all help.