

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 Questions & Answers
- MongoDB - How to copy rows into a newly created collection?
- Listing modified, old and newly created files on Linux using C++
- Display collections in a particular MongoDB database?
- How to create a new database in MongoDB?
- How to create a database in MongoDB using Java?
- Display MySQL Database, Table, and Column Information
- Display the undefined and exact MongoDB document records
- Selecting database inside the JS in MongoDB?
- Where is the MySQL database gets saved when it is created?
- Find objects created in last week in MongoDB?
- Display databases in MongoDB
- Querying only the field name and display only the id in MongoDB?
- Create JList and always display the scroll bar in Java?
- How to create MongoDB user on existing database with correct role?
- Display MongoDB with document and subdocument example and update
Advertisements