Home / Articles / Database / mongodb / 5.0 / create-database

Create Database

Open MongoDB Shell

  • Open the MongoDB Shell from Linux shell
  • # mongosh Current Mongosh Log ID: 6117225c105379b62b6abaa9 Connecting to: mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000 Using MongoDB: 5.0.2 Using Mongosh: 1.0.5 For mongosh info see: https://docs.mongodb.com/mongodb-shell/ test>

Create New Database

  • Create new database from MongoDB shell
  • To create a new Database run the "use db_name" command. This will create a new database if it doesn't exist.

    # use employee switched to db employee
  • Show Current Database
  • employee> db employee
  • Show Database Settings
  • employee> show databases admin 41 kB config 73.7 kB local 41 kB
    employee> db.stats() { db: 'employee', collections: 1, views: 0, objects: 3, avgObjSize: 68.66666666666667, dataSize: 206, storageSize: 36864, freeStorageSize: 16384, indexes: 1, indexSize: 36864, indexFreeStorageSize: 16384, totalSize: 73728, totalFreeStorageSize: 32768, scaleFactor: 1, fsUsedSize: 4024381440, fsTotalSize: 8575254528, ok: 1 }