MongoDB is a cross-platform open-souce, document oriented database that provides, high performance, high availability,automatic aqnd easy scalability , and NoSQL Database.
MongoDB: a document database
A record in mongoDB is a document, which is a data structure composed of field and value pairs.
{
course : 'introduction to NoSQL Database MongoDB',
Category: ["Development","Database"],
Platform:"Online",
instructor: "Muhammad Rehan meo"
}
The Advantages of Using documents
- Documents (i.e. objects) correspond to native data type in many programming languages.
- Embedded documents and arrays reduce need for expensive joins.
- Ability to proform dynamic Queries on documents using document-base Query languages
- Conversion of objects to database objects is not needed
- High performance -uses internal memory to store working set for Quick data access
Install MongoDB On Windows
To install the MongoDB on windows, first doownload the latest release of MongoDB from http://www.mongodb.org/downloads Make sure you get correct version of MongoDB depending upon your windows version. To get your windows version open command prompt and execute following command
C:\>wmic os get osarchitecture
OSArchitecture
64-bit
C:\>
32-bit versions of MongoDB only support databases smaller than 2GB and suitable only for testing and evaluation purposes.
Now extract your downloaded file to c:\ drive or any other location. Make sure name of the extracted folder is mongodb-win32-i386-[version] or mongodb-win32-x86_64-[version]. Here [version] is the version of MongoDB download.
Now open command prompt and run the following command
C:\>move mongodb-win64-* mongodb
1 dir(s) moved.
C:\>
In case you have extracted the mondodb at different location, then go to that path by using command cd FOOLDER/DIR and now run the above given process.
MongoDB requires a data folder to store its files. The default location for the MongoDB data directory is c:\data\db. So you need to create this folder using the Command Prompt. Execute the following
C:\>md data
C:\md data\db
If you have install the MongoDB at different location, then you need to specify any alternate path for \data\db by setting the path dbpath in mongod.exe. For the same issue following commands
In command prompt navigate to the bin directory present into the mongodb installation folder. Suppose my installation folder is D:\set up\mongodb
C:\Users\XYZ>d:
D:\>cd "set up"
D:\set up>cd mongodb
D:\set up\mongodb>cd bin
D:\set up\mongodb\bin>mongod.exe --dbpath "d:\set up\mongodb\data"
This will show waiting for connections message on the console output 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
D:\set up\mongodb\bin>mongo.exe
MongoDB shell version: 2.4.6
connecting to: test
>db.test.save( { a: 1 } )
>db.test.find()
{ "_id" : ObjectId(5879b0f65a56a454), "a" : 1 }
>
This will show that mongodb is installed and run successfully. Next time when you run mongodb you need to issue only commands
D:\set up\mongodb\bin>mongod.exe --dbpath "d:\set up\mongodb\data"
D:\set up\mongodb\bin>mongo.exe
Creating Database and Inserting data in records
Initially, no database is created. But don't worry, they'll instantly be created when we start inserting our records, which we're going to do right now. Copy the content below and paste it in your mongo shell.
D:\mongoDB\bin\mongo
mondoDB shell version: 2.6.4
connecting to: testing
>use myblogs
switched to db myblogs
db.blogs.insert({name: 'mondoDB intro', category: 'Database', tags:['NoSQL','Database','BigData']})
writingResult({"nInserted" : 1})
All good? Excellent! To confirm that the database and accompanying records have been created, type in the following command
>db.blogs.fing()
Result
{"_id": ObjectId("654sds564sdf6842sdfd54"),"name": "mondoDB", "category": "Database", "tags": ["nosoql","database","BigData"]}
Follow this Command for pretty result
>db.blogs.find().pretty()
Result
{
"_id": ObjectId("654sds564sdf6842sdfd54"),
"name": "mondoDB",
"category": "Database",
"tags": [
"NoSQL",
"Database",
"BigData"
]
}
Waiting For More
No comments:
Post a Comment