
- MongoDB Tutorial
- MongoDB - Home
- MongoDB - Overview
- MongoDB - Advantages
- MongoDB - Environment
- MongoDB - Data Modeling
- MongoDB - Create Database
- MongoDB - Drop Database
- MongoDB - Create Collection
- MongoDB - Drop Collection
- MongoDB - Data Types
- MongoDB - Insert Document
- MongoDB - Query Document
- MongoDB - Update Document
- MongoDB - Delete Document
- MongoDB - Projection
- MongoDB - Limiting Records
- MongoDB - Sorting Records
- MongoDB - Indexing
- MongoDB - Aggregation
- MongoDB - Replication
- MongoDB - Sharding
- MongoDB - Create Backup
- MongoDB - Deployment
- MongoDB - Java
- MongoDB - PHP
- Advanced MongoDB
- MongoDB - Relationships
- MongoDB - Database References
- MongoDB - Covered Queries
- MongoDB - Analyzing Queries
- MongoDB - Atomic Operations
- MongoDB - Advanced Indexing
- MongoDB - Indexing Limitations
- MongoDB - ObjectId
- MongoDB - Map Reduce
- MongoDB - Text Search
- MongoDB - Regular Expression
- Working with Rockmongo
- MongoDB - GridFS
- MongoDB - Capped Collections
- Auto-Increment Sequence
- MongoDB Useful Resources
- MongoDB - Questions and Answers
- MongoDB - Quick Guide
- MongoDB - Useful Resources
- MongoDB - Discussion
Create and display the newly created database in MongoDB?
To create a new database, you need to use the USE command as in the below syntax −
use yourDatabaseName;
To show all databases, you need to use show command. The syntax is as follows −
show dbs;
Let us implement the above syntax in order to create database −
> use onlinecustomertracker; switched to db onlinecustomertracker
In order to display the newly created database, you need to create collection. Following is the query −
> db.example.insert({Value:10}); WriteResult({ "nInserted" : 1 })
Display all documents from a collection with the help of find() method −
> db.example.find();
This will produce the following output −
{ "_id" : ObjectId("5e9dafade3c3cd0dcff36a4f"), "Value" : 10 }
To display all databases, you can use SHOW command −
> show dbs;
This will produce the following output −
MyDB 0.000GB admin 0.000GB config 0.000GB local 0.000GB onlinecustomertracker 0.000GB test 0.006GB
- Related Articles
- MongoDB - How to copy rows into a newly created collection?
- Display collections in a particular MongoDB database?
- Listing modified, old and newly created files on Linux using C++
- How to create a new database in MongoDB?
- How to create a database in MongoDB using Java?
- Find objects created in last week in MongoDB?
- How to create MongoDB user on existing database with correct role?
- Selecting database inside the JS in MongoDB?
- Display MySQL Database, Table, and Column Information
- Display databases in MongoDB
- Display the undefined and exact MongoDB document records
- Where is the MySQL database gets saved when it is created?
- Get database data size in MongoDB?
- Querying only the field name and display only the id in MongoDB?
- Get the storage size of a database in MongoDB?

Advertisements