How to Create MongoDB database and Collections
How to Create MongoDB database and Collections
MongoDB is a cross-platform document-oriented database program. Classified as a NoSQL database program, MongoDB uses JSON-like documents with schema. MongoDB is developed by MongoDB Inc. and licensed under the Server Side Public License. After you install MongoDB Please do the following:
1. Connect to the Mongo Shell.
[root@mongotest ~]# mongo mongotest:27017
2. List all Databases.
> show dbs
local 0.031GB
local 0.031GB
3. Create a Database.
> use profiles
switched to db profiles
switched to db profiles
> show dbs
local 0.031GB
4. Show DB still not showing the DB. You need to add at least one Collection to make this DB visible.
> db.Firstname.insert({"name":"Manas"})
WriteResult({ "nInserted" : 1 })
> show dbs
local 0.031GB
profiles 0.031GB
WriteResult({ "nInserted" : 1 })
> show dbs
local 0.031GB
profiles 0.031GB
5. Show all collections.
> show collections
Firstnamesystem.indexes
Firstnamesystem.indexes
6. Show existing DB in Use.
> db
profiles
Useful MongoDB Articles:profiles
- How To Install MongoDB 4 on RHEL 8 / CentOS 8
- How To Install MongoDB 4 on RHEL 7 / CentOS 7
- How to Create MongoDB database and Collections
- MongoDB: Install Mongo Client and Mongo Shell in Ubuntu, CentOS
- How to delete or drop MongoDB database
- MongoDB Startup Error
- MongoDB 3.x Installation and Initial Configuration
No comments