In this digital era, things are moving very vast and for making thing vast technology is playing main role. Proving this term, new technologies are coming with more fast and sharp features, like: MongoDB. MongoDB is playing a vast role in making the apps more efficient and effective. So, I am writing this article for the freshers and experienced who want to use the MongoDB and want to come join the race of technology.
How to install MongoDB
Before installing the MongoDB. Please download the .msi file from the server and follow the below steps.
- Download .msi file for windows as required.
- Install in any drive as required.
- Now create folder “data” >> “db” under any drive which you want to use.
- Create a file with name “mongo.config”(at the same level where bin folder is) and write the below code in it:
##store data here
dbpath=E:\data\db##all output go here
logpath=E:\MongoDB\log\mongo.log##log read and write operations
diaglog=3 - Open cmd and go to the drive under which you have intalled mongodb. Like i have installed in E:\MongoDB
- Now go to bin folder and run
mongod.exe –config=”E:\MongoDB\mongo.config” - Now open new cmd and go to the E:\MongoDB\bin
- Write mongo.exe and press enter
- Congrats MongoDB is installed.
MongoDB is installed on your system. Now, we will learn how to create a database using MongoDB.
How to create database using MongoDB:
- Write in cmd: “use contactlist”
#you will get message switched to db contactlist
#this will create new database and if you want insert the values use the below command: - If you want to insert the values in the database then use: db.contactlist.insert. See the below example:
db.contactlist.insert([{Name:’Gurpal Singh’,Email:’[email protected]’,Number:’111 111 1111′},{Name:’Pranav’,Email:’[email protected]’,Number:’222 222 2222′},{Name:’Punit’,Email:’[email protected]’,Number:'(333)333-3333′}]) - If you want to see the table data which you have inserted then write:
db.contactlist.find()
#too see the contactlist table data - If you want to see the table with pretier way then use:
db.contactlist.find().pretty()
How to use database with our app.
=> Open cmd and go to the directory under which your project has been installed. Like my project is under: E:\nodejsprojects\contactlistapp
=> write “npm install mongojs”
[…] MongoDB is an open source, document-oriented database designed with both scalability and developer agility in mind. Instead of storing your data in tables and rows as you would with a relational database, in MongoDB you store JSON-like documents with dynamic schemas. MongoDB is the next-generation database that lets you create applications never before possible. MongoDB is one of several database types to arise in the mid-2000s under the NoSQL banner. Instead of using tables and rows as in relational databases, MongoDB is built on an architecture of collections and documents. Documents comprise sets of key-value pairs and are the basic unit of data in MongoDB. […]