- MongoDB - PHP
- MongoDB - Java
- MongoDB - Deployment
- MongoDB - Create Backup
- MongoDB - Sharding
- MongoDB - Replication
- MongoDB - Aggregation
- MongoDB - Indexing
- MongoDB - Sorting Records
- MongoDB - Limiting Records
- MongoDB - Projection
- MongoDB - Delete Document
- MongoDB - Update Document
- MongoDB - Query Document
- MongoDB - Insert Document
- MongoDB - Data Types
- MongoDB - Drop Collection
- MongoDB - Create Collection
- MongoDB - Drop Database
- MongoDB - Create Database
- MongoDB - Data Modeling
- MongoDB - Environment
- MongoDB - Advantages
- MongoDB - Overview
- MongoDB - Home
Advanced MongoDB
- Auto-Increment Sequence
- MongoDB - Capped Collections
- MongoDB - GridFS
- Working with Rockmongo
- MongoDB - Regular Expression
- MongoDB - Text Search
- MongoDB - Map Reduce
- MongoDB - ObjectId
- MongoDB - Indexing Limitations
- MongoDB - Advanced Indexing
- MongoDB - Atomic Operations
- MongoDB - Analyzing Queries
- MongoDB - Covered Queries
- MongoDB - Database References
- MongoDB - Relationships
MongoDB Useful Resources
- MongoDB - Discussion
- MongoDB - Useful Resources
- MongoDB - Quick Guide
- MongoDB - Questions and Answers
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
MongoDB - Environment
Let us now see how to install MongoDB on Windows.
Install MongoDB On Windows
To install MongoDB on Windows, first download the latest release of MongoDB from
.Enter the required details, select the Server tab, in it you can choose the version of MongoDB, operating system and, packaging as:
Now install the downloaded file, by default, it will be installed in the folder C:Program Files.
MongoDB requires a data folder to store its files. The default location for the MongoDB data directory is c:datadb. So you need to create this folder using the Command Prompt. Execute the following command sequence.
C:>md data C:md datadb
Then you need to specify set the dbpath to the created directory in mongod.exe. For the same, issue the following commands.
In the command prompt, navigate to the bin directory current in the MongoDB installation folder. Suppose my installation folder is C:Program FilesMongoDB
C:UsersXYZ>d:cd C:Program FilesMongoDBServer4.2in C:Program FilesMongoDBServer4.2in>mongod.exe --dbpath "C:data"
This will show waiting for connections message on the console output, which indicates that the mongod.exe process is running successfully.
Now to run the MongoDB, you need to open another command prompt and issue the following command.
C:Program FilesMongoDBServer4.2in>mongo.exe MongoDB shell version v4.2.1 connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb Imppcit session: session { "id" : UUID("4260beda-f662-4cbe-9bc7-5c1f2242663c") } MongoDB server version: 4.2.1 >
This will show that MongoDB is installed and run successfully. Next time when you run MongoDB, you need to issue only commands.
C:Program FilesMongoDBServer4.2in>mongod.exe --dbpath "C:data" C:Program FilesMongoDBServer4.2in>mongo.exe
Install MongoDB on Ubuntu
Run the following command to import the MongoDB pubpc GPG key −
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
Create a /etc/apt/sources.pst.d/mongodb.pst file using the following command.
echo deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen | sudo tee /etc/apt/sources.pst.d/mongodb.pst
Now issue the following command to update the repository −
sudo apt-get update
Next install the MongoDB by using the following command −
apt-get install mongodb-10gen = 4.2
In the above installation, 2.2.3 is currently released MongoDB version. Make sure to install the latest version always. Now MongoDB is installed successfully.
Start MongoDB
sudo service mongodb start
Stop MongoDB
sudo service mongodb stop
Restart MongoDB
sudo service mongodb restart
To use MongoDB run the following command.
mongo
This will connect you to running MongoDB instance.
MongoDB Help
To get a pst of commands, type db.help() in MongoDB cpent. This will give you a pst of commands as shown in the following screenshot.
MongoDB Statistics
To get stats about MongoDB server, type the command db.stats() in MongoDB cpent. This will show the database name, number of collection and documents in the database. Output of the command is shown in the following screenshot.
Advertisements