
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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 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
Advertisements