Databases In MongoDB

Share via:

Databases In MongoDB

In MongoDB the databases are divided in to two types based on the data they store they are.
1. Default databases
2. Non default databases
Non default databases: The databases that are created explicitly depend on the needs of the users.
Default databases: The databases that are automatically created when you install the MongoDB and run the MongoDB instance.
They are three default databases, and each database has their own specification,
The Three default databases are.
1. Admin
2. Local
3. Config

 

1. Admin database:
♦ The admin database is used to store the administrative data like user and role management, managing the permissions.
♦ The admin database is not visible for the regular users; only root users can access the data in the admin database.
♦ This provides security to MongoDB through authentication.
♦ The admin database is not sharded.
♦ All the replica set members can access the admin database.
♦ Some of the collections that present in the admin database are.
• system.users
• system.roles
• system.version
• system.index

 

2. Local database:
♦ The local database is used to store the data about the MongoDB instance, this includes the database and collection list, oplog , startup log and the transactions while querying the data and helps in tracking the health of MongoDB instance.
♦ The local database is not replicated i.e., local database is available to the MongoDB instance where it was created.
♦ Some of the collections that present in the local database are.
• oplog.rs
• startup_log
• diagonistic.log

 

3. Config database:
♦ The config database is used to store the metadata which is used to manage the shared clusters or clusters.
♦ Config database is read only database i.e., users can’t modify the data which is present in the config database.
♦ The config database is stored on the config servers in the cluster. The config servers used to store metadata for the sharded clusters which is used to manage the distribution of data in the cluster.
♦ Config database is replicated.
♦ Some of the collections that present in the config database are.
• config.databases
• config.collections
• config.chunks
When you start the MongoDB instance all the default databases are created automatically which are not used to store the user specified data.
The below picture will show the default databases that are created when you run the MongoDB instance in your system.

Non default databases:
♦ Databases that are created by user based on their requirement.
♦ User can create multiple databases.
♦ To create a database in MongoDB you have to use the “use” command.
♦ When you create a database in MongoDB that must contain at least one collection, without the collection the database will not be created.
For example, when you want to create the database named New_DB we follow the below command.
Command: use New_DB
Look the below picture that contains both the default and non-default databases.

We can add the collection to the database in two ways.
1. Using createCollection
Command: db.createCollection(“collection_name”)
2. By inserting the data into collection without creating the collection
Command: db.collection_name.insert({document})

 

Naming Conventions for Databases in MongoDB
1. Name of the database should not be null and try to maintain case sensitive names.
2. Length of database must be less than 64 characters.
3. Should not contains the following characters “/”, ”\”, ”.”, “””, ”$”, *”, “<”,”>”, “:”, “|”, “?”

 

Author    : Teja
LinkedIn : https://www.linkedin.com/in/teja-sai-nadh-reddy-tatireddy-048882201
Thank you for giving your valuable time to read the above information. Please click here to subscribe for further updates
KTExperts is always active on social media platforms.
Facebook  : https://www.facebook.com/ktexperts/
LinkedIn    : https://www.linkedin.com/company/ktexperts/
Twitter       : https://twitter.com/ktexpertsadmin
YouTube   :  https://www.youtube.com/c/ktexperts
Instagram  : https://www.instagram.com/knowledgesharingplatform
Share via:
Note: Please test scripts in Non Prod before trying in Production.
1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading...

Add Comment