MongoDB for multiple apps

I have been doing many fullstack tutorials to learn the MERN stack. But I can only sign up for one free cluster on MongoDB. When I try to create multiple apps using one (the same) cluster, I get an error:

errmsg: 'E11000 duplicate key error collection: test.users index: username_1 dup key: { username: null }

If I delete my old free cluster and make a new one, this error goes away.

My question is, should I be able to use one cluster for multiple applications? I tried changing the names of my schema, database variable, model file name, etc. but I could only get the duplicate key error to go away by deleting my old cluster and starting fresh with a new one - of course this means the first app I created won’t work now. I will only be able to use my most recent fullstack app with my free cluster.

I also have this problem and a forum search brought me here. The project guide says

Feel free to create separate databases for different applications if they need a separate database. You just need to create a new project under your current MongoDB Atlas account, build a new cluster, add a new user, whitelist your IP addresses and finally connect to your cluster to obtain the new URI.

I interpreted this (rightly or wrongly) to mean we could we could get through the projects on the free tier by just building a new cluster. But we have to start paying. Of course, like the OP says, you could throw away a previous project but then why are we submitting links to projects that will disappear? I’m curious about what was the original idea. I watched a video in which a valid solution was achieved without a database. Even though the short URLs didn’t persist after a Glitch restart, it passed the test. I am happy to do that if that is what is expected but it seems a waste not to use what I just learned in the mongodb part of the course.

Hello folks~!
Here’s what I’ve done:

This is a list of databases in my Cluster 0. Each database ties to a different project, so I can run them concurrently. All you need to do is click “Create Database”, then name your database and your first collection. I usually name my first collection “initial”, then delete it when my app has generated a new collection from the Schema name.

To tell your app which collection to connect to, replace “test” in this sample URI with the name of the collection you want that app to use.

No need to create a new cluster or pay for additional service. At least, this has been sufficient enough for the FCC projects.

1 Like

Thanks! That’s what I hoped. Hope the guidance changes so that everyone knows how to do this upfront.

That works well and I don’t need to create a new email account for every project!

I just create a new gmail account when I want a new free cluster. You can have unlimited clusters this way.