What are admin, config, and local ? in Mongo db Compass !
In MongoDB, admin, config, and local are special system databases that serve specific purposes within the database ecosystem. Here's an explanation of each:
1. admin Database
- Purpose: The admin database is used for administrative tasks and configuration. It serves as the central database for managing the MongoDB instance.
- Key Features:
- It contains system collections for user authentication and role-based access control.
- Admin users created here can have privileges across all databases in the MongoDB instance.
- It's used to issue administrative commands (e.g., shutting down the server, modifying cluster configuration).
- Some commands like
db.shutdownServer()
,db.serverStatus()
, and replication commands require access to the admin database.
- Example: If a user is created in the admin database with root privileges, they can perform operations on all databases.
2. config Database
- Purpose: The config database is used in a sharded cluster to store metadata and configuration details for the cluster.
- Key Features:
- It contains information about shards, databases, and collections in a sharded setup.
- Tracks chunk distribution and migrations between shards.
- Helps the MongoDB query router (
mongos
) to determine where specific data resides. - It is crucial for sharded cluster operation.
- Example: When you use sharding, the config database contains collections such as
config.chunks
(to track data chunks) andconfig.databases
(to track databases in the cluster).
3. local Database
- Purpose: The local database stores data specific to a single server instance. This data is not replicated and is specific to the node.
- Key Features:
- Used in replication to store the oplog (operation log), which is essential for keeping replicas in sync.
- Contains metadata and temporary data for the local node.
- Data stored here does not get replicated to other nodes in a replica set.
- Example:
- In a replica set, the local.oplog.rs collection contains the operation log that records changes to the database.
- It also contains the
replSet
configuration used for replication.
Summary Table:
Database | Purpose | Key Use Cases |
---|---|---|
admin | Central administrative database | Managing users, roles, and issuing commands |
config | Sharded cluster metadata | Metadata for sharding (chunks, shard info) |
local | Node-specific data | Oplog for replication and local configuration |
These databases are reserved for system use and are critical for MongoDB's functionality. You typically don't store application data in these databases.