Db connection with Atlas, dev and prod part (using node+express)

Hello,
I have the task to create a db for development and production.
The development part works. I access MongoDB via mongoose. (node+express backend).

I use Atlas for setting up MongoDB. I have a connection string user+password.

Since I come from the php+mysql world, things are abit confusion for me.
When I add a new db, I think I have to open a new project (because I take the free Atlas version for now)

Then _I have to setup a cluster. But cluster is only hardware, isn’t it? How do I add the new db then, within that cluster or within the new project? Thanks a lot!

Hi @Marco_A and welcome in the MongoDB Community !

First, yes, you are correct, you can only have one M0 cluster per Atlas project. So if you want your dev and prod running on an M0 cluster, you will have to create 2 Atlas projects.

That being said, M0 are just shared instances and are not reliable enough for production environment. Please consider using at least an M10 for a production environment which is the first dedicated tier.

When you create a cluster in Atlas, which ever tier you create from M0 to M700, by default it’s a replica set of 3 machines running in the background. The cluster you see on Atlas is “just” the hardware + the mongod daemons running (and configured correctly).

Databases lives inside the cluster. If you want to create a database, head into the collection tab:

Then click on “create databse”.

You will also have the option their to create a collection which is a set of documents. A collection lives inside a database.

That being said, you don’t need to create any database or collection. In MongoDB, they are created automatically when you write the first document in them.

Example:

test:PRIMARY> use new_database
switched to db new_database
test:PRIMARY> db.new_collection.insert({"new":"document"})
WriteResult({ "nInserted" : 1 })
test:PRIMARY> db.new_collection.findOne()
{ "_id" : ObjectId("60217d05fefe8bffdab5ee20"), "new" : "document" }
test:PRIMARY> show dbs 
admin         0.000GB
config        0.000GB
local         0.000GB
new_database  0.000GB
test          0.000GB
test:PRIMARY> show collections
new_collection

I hope this helps.

Cheers,
Maxime.

Hi Maxime, thanks a lot for the answer.

Mmmhh… now I’m really a bit confused. With mysql, I create my database and populate that with tables. I can then define the primary key for a table and so on…

I heard that MongoDB only uses JSON. Do these documents consists of JSON formatted data then?

1 Like

Yup, that’s correct.

I found this that might help you understand the “equivalent” between the 2.

image

Also, you should really consider our MongoDB Basics course on our University: MongoDB Courses and Trainings | MongoDB University.

It’s completely free and it will just take a few hours for you to understand all the basics of MongoDB :slight_smile:.

Then we also have more advanced courses if you want to learn more: MongoDB Courses and Trainings | MongoDB University

Cheers,
Maxime.

I will check those links, thanks a lot for the information!

1 Like

You are very welcome.

If you prefer tutos, we have a bunch of Node.js content as well on the DevHub:

https://www.mongodb.com/learn/?text=Node.js

Cheers,
Maxime.

I do most of the things with mySQL but thanks a lot!