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:
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
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?