SlideShare ist ein Scribd-Unternehmen logo
1 von 24
MongoDB Basic Installation
Mr. Parkhe Kishor B.
Sr. Software Engineer
Highmark Credit Information Services Pvt. Ltd., Pune
Email: parkhekishor@gmail.com Mobile No. +919595745346
email: parkhekishor@gmail.com Mobile
No. +919595745346
MongoDB Basic Installation
This guide shows, how to install MongoDB on Windows and Centos.
1. Windows installation
2. Centos Installation
Step 1.1
Download latest production release MongoDB from MongoDB download page .
There are three build of for MongoDB.
Windows server 2008 R2
Windows 64 bits
Windows 32 bits (development up to 2GB)
Note: Type following commend in the command prompt to find architecture of
your windows platform.
C:>wmic os get osarchitecture
OSArchitecture
32-bit
email: parkhekishor@gmail.com Mobile
No. +919595745346
Step 1.2:
Start command prompt, create data folder for MongoDB.(default location
c:datadb).
This will start main MongoDB database process and waiting for connection
message in console
email: parkhekishor@gmail.com Mobile
No. +919595745346
Step 1.3:
Copy MongoDB download package into
C: MongoDB folder and unzip
email: parkhekishor@gmail.com Mobile
No. +919595745346
Step 1.4:
Connect to MongoDB using mongo.exe
Open another command prompt and issue the following commands
C:MongoDBmongodb-win32-i386-2.2.2bin>mongo.exe
mongo.exe will connect mongod.exe running on local host interface on
27017 port .
you can check http services at http://localhost:28017
Step 1.5:
test database and retrieve records. Type following commands in mongo
shell
>db.test.save ( , a : “test”- )
>db.test.find()
{ "_id" : ObjectId("50f8f47dc49f1d211f947d60"), "a" : "test" }
>
email: parkhekishor@gmail.com Mobile
No. +919595745346
2. CentOS Installation
Step 2.1 :
Download latest production release MongoDB from MongoDB download page .
• There are two build of for MongoDB.
• Linux 64 bits
• Linux 32 bits (development up to 2GB)
Step 2.2 :
Start terminal create data folder for MongoDB.(default location root#datadb).
Step 2.3 :
Copy MongoDB download package into rootMongoDB folder and unzip.
then go to bin folder of MongoDB package and type commands
./mongod
this will start main MongoDB database process.
email: parkhekishor@gmail.com Mobile
No. +919595745346
Step 1.4:
Connect to MongoDB using mongo.exe
Open another command prompt and issue the following commands
[root@HMCLUSTER2 /]# cd mongodb-linux-x86_64-2.0.6/bin
[root@HMCLUSTER2 bin]# ./mongo
mongo.rpm will connect mongod.rpm running on local host interface on 27017
port .
you can check http services at http://localhost:28017
Step 1.5:
test database and retrieve records. Type following commands in mongo shell
>db.test.save ( , a : “test”- )
>db.test.find()
{ "_id" : ObjectId("50f8f47dc49f1d211f947d60"), "a" : "test" }
>
email: parkhekishor@gmail.com Mobile
No. +919595745346
Connecting to Database
1. From command prompt start mongo. By default mongo look for database
server on local host on the port 27017.
2. To connect server on different port or interface use the --port and --host
3. Select data base use command db, it show name of current database.
4. To list all database use command in mongo shell
show dbs.
5. Switch to new database name mydb with following operation
use db name
6. Show mongo help in mongo shell using following operation
help
email: parkhekishor@gmail.com Mobile
No. +919595745346
Create collection and insert Documents
1. Switch to mydb with following operation
use mydb
2. Create two document name doc1 and doc2 using JavaScript operation
doc1 = ,name : “mongo” -
doc2 = {x: 1}
3. Insert two document into collection say blog with following operation
db.blog.insert( doc1)
db.blog.insert( doc2)
when you insert document then MongoDB create both database mydb and blog
collection.
4. Confirm that collection is exist with following commands,
show collections
5. Conform that document insert in collection using find () methods
db.blog.find();
6. Inserting multiple documents using for loop.
email: parkhekishor@gmail.com Mobile
No. +919595745346
Implementing Curser
1. When you querying, MongoDB return curser object that contain result of
query.
2. Iterating over the curser with loop
var curser= db.blog.find();
while( curser.hasnext() ){
printjson( curser.next() );
}
3. Use array operation with curser
curser[4];
email: parkhekishor@gmail.com Mobile
No. +919595745346
Querying for Specific Documents
1. define query
q=, Field : “condition” -
By passing this query document as parameter to find() method.
db.blog.find(q) or db.blog.find( , field : “condition” - )
2. Query and Projection
e.g. doc1= , id : 1, name : “mongo” -
to find all docs where id has a value 1 but return only name.
query = { id : 1 } and projection = { name : 1}
db.blog.find(query, projection)
MongoDB return the following result,
,name : “mongo” -
3. Limiting number of document in result set
db.blog.find().limit(3)
email: parkhekishor@gmail.com Mobile
No. +919595745346
Core MongoDB Operation
1. Create
2. Read
3. Update
4. Delete
Restriction on document
_id field must be unique in collection
The field name can not start with the $ character
The field name can not start with the . Character
1 Create
1.1 insert and bulk insert
1.2 create with save
1.3 create with upsert
email: parkhekishor@gmail.com Mobile
No. +919595745346
2 Read operation
2.1 find
2.2 findOne
2.3 projection
3 Update
3.1 update field ($set)
3.2 update array ($push)
3.3 update and upsert (true or 1)
3.4 update multiple matching documents
4 DELETE
4.1 remove collection
4.2 remove matching documents
4.3 remove single matching documents
email: parkhekishor@gmail.com Mobile
No. +919595745346
Querying
1. Specifying which query return
Example consider following document,
, id : ObjetcId(….),
name : Ram,
age : 16,
email : ram@gmail.com,
city : pune,
pin : 413710
}
email: parkhekishor@gmail.com Mobile
No. +919595745346
1. You have user collection, if you are interested only in name and email
fields,
> db.user.find (, -, , “name” : 1, “email “: 1- )
Out put
{
“_id” : (…),
name : “ram”,
email : ram@gmail.com
}
2. Conditional Query
> db.user.find ( , “name” : “ram” - )
Out put
, id : ObjetcId(….),
name : Ram, age : 16, email : ram@gmail.com,
city : pune,
pin : 413710
}
email: parkhekishor@gmail.com Mobile
No. +919595745346
3 . Query Conditionals
“$lt” = “<“
“$gt” =“>”
“$lte” =“<=“
“$gte”=“>=“ are all comparison operators.
> db.user.find(, “age” : ,$gt : 10- -)
It gives all which has age greater than 10.
>db.user.find(, “age” : ,$gt : 10 ,$lt : 50- -)
it return all documents, field age in 10 to 50 range.
> db.user.find ({"name" : { "$ne" : "ram" } })
Out put
{ "_id" : ObjectId("50ff718bc5d2a43b68806826"), "name" :
"ram1", "email" : "ram@gmail.com", "id" : "10" }
email: parkhekishor@gmail.com Mobile
No. +919595745346
4. OR Queries
There are two way to do OR query in MongoDB
4.1 “$in”
If you have more than one possible value to match for a single key, then
use array criteria
> db.user.find (,"name" : , "$in" : *“ram”, “ram1” + - -)
opposite of “$in” is “$nin” which return all documents that don’t match
any of criteria.
4.2 “$or”
>db.user.find(,"$or" : *,“name" : “ram” -, ,“age" : 10-+-)
this query return all documents that satisfy either name or age criteria.
4.3 “$and”
by using “AND” query you can narrow result set.
>db.user.find(,"$and" : *,“name" : “ram” -, ,“age" : 10-+-)
email: parkhekishor@gmail.com Mobile
No. +919595745346
4.4 “$not”
> db.user.find({".id1" : {$not :{$gt: 11}} })
{ "_id" : ObjectId("50ff6950c5d2a43b68806825"), { "name" :
"ram", "email" : "ram@gmail.com", "id" : "10" }
{ "_id" : ObjectId("50ff718bc5d2a43b68806826"), "name" :
"ram1", "email" : "ram@gmail.com", "id" : "10" }
{ "_id" : ObjectId("50ff7efdc5d2a43b68806827"), "name" :
"ram1", "email" : "ram@gmail.com", "id1" : 10 }
4.5 Regular expression
Regular expressions are flexible for string matching.
> db.user.find({"name" : /ram/i -) ‘i ‘ use for case - insensitive.
email: parkhekishor@gmail.com Mobile
No. +919595745346
Querying Array
Example suppose array is a list of colors,
1 like this:
> db.user.insert({colors : [ "red" , "white" ,"green", "black"]})
the following query:
> db.user.find({colors : "red"})
Out put:
{ "_id" : ObjectId("50ff83f9c5d2a43b68806829"), "colors" : [
"red", "white", "green", "black" ] }
2 if you need to match array more than on element the you use $all,
> db.user.find(,colors : ,$all : *"red“ , “ black " +--)
{ "_id" : ObjectId("50ff83f9c5d2a43b68806829"), "colors" : [
"red", "white", "green", "black" ] }
email: parkhekishor@gmail.com Mobile
No. +919595745346
3 “$size”
this operator allow you query to array of given size.
>db.user.find ( { colors : {$size : 3} )
this can’t be combine with another $ conditional operator (like $gt ).
4 “$slice”
The special "$slice" operator can be used to return a subset of elements
for an array key.
for example we had a blog post collection and we wanted first 10
comments.
>db.blog.posts.findOne(criteria, {"comments" : {"$slice" : 10}})
Alternatively you find last 10 comments
>db.blog.posts.findOne(criteria, {"comments" : {"$slice" : -10}})
email: parkhekishor@gmail.com Mobile
No. +919595745346
"$slice" can also return pages in the middle of the results by taking an
offset and the number of elements to return:
> db.blog.posts.findOne(criteria, {"comments" : {"$slice" : [23, 10]}})
this would keep first 23 elements and return 24th to 34th.
email: parkhekishor@gmail.com Mobile
No. +919595745346
Querying Embedded Documents
There are two ways querying embedded documents
1 Query for whole document
2 Query for individual document
Example : {
name : {
first : “ram” ,
last : “roy”
}
}
First query for whole document
> db.user.find(, name : name : , first : “ram” ,last : “sharma” - -
email: parkhekishor@gmail.com Mobile
No. +919595745346
Query for just a specific key or keys of an embedded document.
>db.user.find( , “name.first” : “ram”-)
Example
{
"content" : “what is MongoDB? ",
"comments" : [
{
"author" : “ram",
"score" : 3,
"comment" : "nice post"
},
{
"author" : “sham",
"score" : 6,
"comment" : "terrible post"
}
]
}
email: parkhekishor@gmail.com Mobile
No. +919595745346
Complex query
To find documents comments by ram, issue following commands,
>db.user.find(, comments : , author : “ram” - -)
alternatively
>db.user.find(, “comments.author” : “ram” -)
email: parkhekishor@gmail.com Mobile
No. +919595745346

Weitere ähnliche Inhalte

Was ist angesagt?

Storing tree structures with MongoDB
Storing tree structures with MongoDBStoring tree structures with MongoDB
Storing tree structures with MongoDBVyacheslav
 
What do you mean, Backwards Compatibility?
What do you mean, Backwards Compatibility?What do you mean, Backwards Compatibility?
What do you mean, Backwards Compatibility?Trisha Gee
 
Indexing & query optimization
Indexing & query optimizationIndexing & query optimization
Indexing & query optimizationJared Rosoff
 
Intro to MongoDB and datamodeling
Intro to MongoDB and datamodeling Intro to MongoDB and datamodeling
Intro to MongoDB and datamodeling rogerbodamer
 
dotSwift - From Problem to Solution
dotSwift - From Problem to SolutiondotSwift - From Problem to Solution
dotSwift - From Problem to Solutionsoroushkhanlou
 
MongoDB .local Munich 2019: Aggregation Pipeline Power++: How MongoDB 4.2 Pip...
MongoDB .local Munich 2019: Aggregation Pipeline Power++: How MongoDB 4.2 Pip...MongoDB .local Munich 2019: Aggregation Pipeline Power++: How MongoDB 4.2 Pip...
MongoDB .local Munich 2019: Aggregation Pipeline Power++: How MongoDB 4.2 Pip...MongoDB
 
Back to Basics: My First MongoDB Application
Back to Basics: My First MongoDB ApplicationBack to Basics: My First MongoDB Application
Back to Basics: My First MongoDB ApplicationMongoDB
 
MongoD Essentials
MongoD EssentialsMongoD Essentials
MongoD Essentialszahid-mian
 
The Ring programming language version 1.5.3 book - Part 43 of 184
The Ring programming language version 1.5.3 book - Part 43 of 184The Ring programming language version 1.5.3 book - Part 43 of 184
The Ring programming language version 1.5.3 book - Part 43 of 184Mahmoud Samir Fayed
 
ETL for Pros: Getting Data Into MongoDB
ETL for Pros: Getting Data Into MongoDBETL for Pros: Getting Data Into MongoDB
ETL for Pros: Getting Data Into MongoDBMongoDB
 
Indexing Strategies to Help You Scale
Indexing Strategies to Help You ScaleIndexing Strategies to Help You Scale
Indexing Strategies to Help You ScaleMongoDB
 
Back to Basics Webinar 5: Introduction to the Aggregation Framework
Back to Basics Webinar 5: Introduction to the Aggregation FrameworkBack to Basics Webinar 5: Introduction to the Aggregation Framework
Back to Basics Webinar 5: Introduction to the Aggregation FrameworkMongoDB
 
Reading the .explain() Output
Reading the .explain() OutputReading the .explain() Output
Reading the .explain() OutputMongoDB
 
The Ring programming language version 1.5.4 book - Part 44 of 185
The Ring programming language version 1.5.4 book - Part 44 of 185The Ring programming language version 1.5.4 book - Part 44 of 185
The Ring programming language version 1.5.4 book - Part 44 of 185Mahmoud Samir Fayed
 
Error based blind sqli
Error based blind sqliError based blind sqli
Error based blind sqliDarkZtone Zone
 

Was ist angesagt? (19)

Mongo db for C# Developers
Mongo db for C# DevelopersMongo db for C# Developers
Mongo db for C# Developers
 
Storing tree structures with MongoDB
Storing tree structures with MongoDBStoring tree structures with MongoDB
Storing tree structures with MongoDB
 
What do you mean, Backwards Compatibility?
What do you mean, Backwards Compatibility?What do you mean, Backwards Compatibility?
What do you mean, Backwards Compatibility?
 
Indexing & query optimization
Indexing & query optimizationIndexing & query optimization
Indexing & query optimization
 
Intro to MongoDB and datamodeling
Intro to MongoDB and datamodeling Intro to MongoDB and datamodeling
Intro to MongoDB and datamodeling
 
dotSwift - From Problem to Solution
dotSwift - From Problem to SolutiondotSwift - From Problem to Solution
dotSwift - From Problem to Solution
 
MongoDB .local Munich 2019: Aggregation Pipeline Power++: How MongoDB 4.2 Pip...
MongoDB .local Munich 2019: Aggregation Pipeline Power++: How MongoDB 4.2 Pip...MongoDB .local Munich 2019: Aggregation Pipeline Power++: How MongoDB 4.2 Pip...
MongoDB .local Munich 2019: Aggregation Pipeline Power++: How MongoDB 4.2 Pip...
 
Back to Basics: My First MongoDB Application
Back to Basics: My First MongoDB ApplicationBack to Basics: My First MongoDB Application
Back to Basics: My First MongoDB Application
 
MongoD Essentials
MongoD EssentialsMongoD Essentials
MongoD Essentials
 
The Ring programming language version 1.5.3 book - Part 43 of 184
The Ring programming language version 1.5.3 book - Part 43 of 184The Ring programming language version 1.5.3 book - Part 43 of 184
The Ring programming language version 1.5.3 book - Part 43 of 184
 
ETL for Pros: Getting Data Into MongoDB
ETL for Pros: Getting Data Into MongoDBETL for Pros: Getting Data Into MongoDB
ETL for Pros: Getting Data Into MongoDB
 
Indexing Strategies to Help You Scale
Indexing Strategies to Help You ScaleIndexing Strategies to Help You Scale
Indexing Strategies to Help You Scale
 
Mongo indexes
Mongo indexesMongo indexes
Mongo indexes
 
Back to Basics Webinar 5: Introduction to the Aggregation Framework
Back to Basics Webinar 5: Introduction to the Aggregation FrameworkBack to Basics Webinar 5: Introduction to the Aggregation Framework
Back to Basics Webinar 5: Introduction to the Aggregation Framework
 
Reading the .explain() Output
Reading the .explain() OutputReading the .explain() Output
Reading the .explain() Output
 
The Ring programming language version 1.5.4 book - Part 44 of 185
The Ring programming language version 1.5.4 book - Part 44 of 185The Ring programming language version 1.5.4 book - Part 44 of 185
The Ring programming language version 1.5.4 book - Part 44 of 185
 
Error based blind sqli
Error based blind sqliError based blind sqli
Error based blind sqli
 
Procedures
ProceduresProcedures
Procedures
 
03DOM.ppt
03DOM.ppt03DOM.ppt
03DOM.ppt
 

Ähnlich wie Mongo db basic installation

Back to Basics Webinar 2 - Your First MongoDB Application
Back to  Basics Webinar 2 - Your First MongoDB ApplicationBack to  Basics Webinar 2 - Your First MongoDB Application
Back to Basics Webinar 2 - Your First MongoDB ApplicationJoe Drumgoole
 
Back to Basics Webinar 2: Your First MongoDB Application
Back to Basics Webinar 2: Your First MongoDB ApplicationBack to Basics Webinar 2: Your First MongoDB Application
Back to Basics Webinar 2: Your First MongoDB ApplicationMongoDB
 
Dev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDBDev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDBMongoDB
 
Back to Basics, webinar 2: La tua prima applicazione MongoDB
Back to Basics, webinar 2: La tua prima applicazione MongoDBBack to Basics, webinar 2: La tua prima applicazione MongoDB
Back to Basics, webinar 2: La tua prima applicazione MongoDBMongoDB
 
Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...
Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...
Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...MongoDB
 
Superficial mongo db
Superficial mongo dbSuperficial mongo db
Superficial mongo dbDaeMyung Kang
 
Dev Jumpstart: Building Your First App
Dev Jumpstart: Building Your First AppDev Jumpstart: Building Your First App
Dev Jumpstart: Building Your First AppMongoDB
 
Beyond PHP - It's not (just) about the code
Beyond PHP - It's not (just) about the codeBeyond PHP - It's not (just) about the code
Beyond PHP - It's not (just) about the codeWim Godden
 
Back to Basics 2017 - Your First MongoDB Application
Back to Basics 2017 - Your First MongoDB ApplicationBack to Basics 2017 - Your First MongoDB Application
Back to Basics 2017 - Your First MongoDB ApplicationJoe Drumgoole
 
Sekilas PHP + mongoDB
Sekilas PHP + mongoDBSekilas PHP + mongoDB
Sekilas PHP + mongoDBHadi Ariawan
 
MongoDB for Coder Training (Coding Serbia 2013)
MongoDB for Coder Training (Coding Serbia 2013)MongoDB for Coder Training (Coding Serbia 2013)
MongoDB for Coder Training (Coding Serbia 2013)Uwe Printz
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBAlex Bilbie
 
Introduction to MongoDB at IGDTUW
Introduction to MongoDB at IGDTUWIntroduction to MongoDB at IGDTUW
Introduction to MongoDB at IGDTUWAnkur Raina
 
MongoDB, PHP and the cloud - php cloud summit 2011
MongoDB, PHP and the cloud - php cloud summit 2011MongoDB, PHP and the cloud - php cloud summit 2011
MongoDB, PHP and the cloud - php cloud summit 2011Steven Francia
 
My First Cluster with MongoDB Atlas
My First Cluster with MongoDB AtlasMy First Cluster with MongoDB Atlas
My First Cluster with MongoDB AtlasJay Gordon
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBMongoDB
 

Ähnlich wie Mongo db basic installation (20)

Back to Basics Webinar 2 - Your First MongoDB Application
Back to  Basics Webinar 2 - Your First MongoDB ApplicationBack to  Basics Webinar 2 - Your First MongoDB Application
Back to Basics Webinar 2 - Your First MongoDB Application
 
Back to Basics Webinar 2: Your First MongoDB Application
Back to Basics Webinar 2: Your First MongoDB ApplicationBack to Basics Webinar 2: Your First MongoDB Application
Back to Basics Webinar 2: Your First MongoDB Application
 
Dev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDBDev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDB
 
Back to Basics, webinar 2: La tua prima applicazione MongoDB
Back to Basics, webinar 2: La tua prima applicazione MongoDBBack to Basics, webinar 2: La tua prima applicazione MongoDB
Back to Basics, webinar 2: La tua prima applicazione MongoDB
 
Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...
Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...
Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...
 
Superficial mongo db
Superficial mongo dbSuperficial mongo db
Superficial mongo db
 
Dev Jumpstart: Building Your First App
Dev Jumpstart: Building Your First AppDev Jumpstart: Building Your First App
Dev Jumpstart: Building Your First App
 
MongoDB (Advanced)
MongoDB (Advanced)MongoDB (Advanced)
MongoDB (Advanced)
 
Mongo db basics
Mongo db basicsMongo db basics
Mongo db basics
 
Beyond PHP - It's not (just) about the code
Beyond PHP - It's not (just) about the codeBeyond PHP - It's not (just) about the code
Beyond PHP - It's not (just) about the code
 
Back to Basics 2017 - Your First MongoDB Application
Back to Basics 2017 - Your First MongoDB ApplicationBack to Basics 2017 - Your First MongoDB Application
Back to Basics 2017 - Your First MongoDB Application
 
Sekilas PHP + mongoDB
Sekilas PHP + mongoDBSekilas PHP + mongoDB
Sekilas PHP + mongoDB
 
MongoDB for Coder Training (Coding Serbia 2013)
MongoDB for Coder Training (Coding Serbia 2013)MongoDB for Coder Training (Coding Serbia 2013)
MongoDB for Coder Training (Coding Serbia 2013)
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Introduction to MongoDB at IGDTUW
Introduction to MongoDB at IGDTUWIntroduction to MongoDB at IGDTUW
Introduction to MongoDB at IGDTUW
 
An introduction to MongoDB
An introduction to MongoDBAn introduction to MongoDB
An introduction to MongoDB
 
MongoDB, PHP and the cloud - php cloud summit 2011
MongoDB, PHP and the cloud - php cloud summit 2011MongoDB, PHP and the cloud - php cloud summit 2011
MongoDB, PHP and the cloud - php cloud summit 2011
 
My First Cluster with MongoDB Atlas
My First Cluster with MongoDB AtlasMy First Cluster with MongoDB Atlas
My First Cluster with MongoDB Atlas
 
Mongo db dla administratora
Mongo db dla administratoraMongo db dla administratora
Mongo db dla administratora
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 

Mehr von Kishor Parkhe

Aggregation in MongoDB
Aggregation in MongoDBAggregation in MongoDB
Aggregation in MongoDBKishor Parkhe
 
Getting started with replica set in MongoDB
Getting started with replica set in MongoDBGetting started with replica set in MongoDB
Getting started with replica set in MongoDBKishor Parkhe
 
C aptitude 1st jan 2012
C aptitude 1st jan 2012C aptitude 1st jan 2012
C aptitude 1st jan 2012Kishor Parkhe
 

Mehr von Kishor Parkhe (6)

Big data and hadoop
Big data and hadoopBig data and hadoop
Big data and hadoop
 
Redis
RedisRedis
Redis
 
Aggregation in MongoDB
Aggregation in MongoDBAggregation in MongoDB
Aggregation in MongoDB
 
Indexing In MongoDB
Indexing In MongoDBIndexing In MongoDB
Indexing In MongoDB
 
Getting started with replica set in MongoDB
Getting started with replica set in MongoDBGetting started with replica set in MongoDB
Getting started with replica set in MongoDB
 
C aptitude 1st jan 2012
C aptitude 1st jan 2012C aptitude 1st jan 2012
C aptitude 1st jan 2012
 

Kürzlich hochgeladen

From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 

Kürzlich hochgeladen (20)

From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 

Mongo db basic installation

  • 1. MongoDB Basic Installation Mr. Parkhe Kishor B. Sr. Software Engineer Highmark Credit Information Services Pvt. Ltd., Pune Email: parkhekishor@gmail.com Mobile No. +919595745346 email: parkhekishor@gmail.com Mobile No. +919595745346
  • 2. MongoDB Basic Installation This guide shows, how to install MongoDB on Windows and Centos. 1. Windows installation 2. Centos Installation Step 1.1 Download latest production release MongoDB from MongoDB download page . There are three build of for MongoDB. Windows server 2008 R2 Windows 64 bits Windows 32 bits (development up to 2GB) Note: Type following commend in the command prompt to find architecture of your windows platform. C:>wmic os get osarchitecture OSArchitecture 32-bit email: parkhekishor@gmail.com Mobile No. +919595745346
  • 3. Step 1.2: Start command prompt, create data folder for MongoDB.(default location c:datadb). This will start main MongoDB database process and waiting for connection message in console email: parkhekishor@gmail.com Mobile No. +919595745346
  • 4. Step 1.3: Copy MongoDB download package into C: MongoDB folder and unzip email: parkhekishor@gmail.com Mobile No. +919595745346
  • 5. Step 1.4: Connect to MongoDB using mongo.exe Open another command prompt and issue the following commands C:MongoDBmongodb-win32-i386-2.2.2bin>mongo.exe mongo.exe will connect mongod.exe running on local host interface on 27017 port . you can check http services at http://localhost:28017 Step 1.5: test database and retrieve records. Type following commands in mongo shell >db.test.save ( , a : “test”- ) >db.test.find() { "_id" : ObjectId("50f8f47dc49f1d211f947d60"), "a" : "test" } > email: parkhekishor@gmail.com Mobile No. +919595745346
  • 6. 2. CentOS Installation Step 2.1 : Download latest production release MongoDB from MongoDB download page . • There are two build of for MongoDB. • Linux 64 bits • Linux 32 bits (development up to 2GB) Step 2.2 : Start terminal create data folder for MongoDB.(default location root#datadb). Step 2.3 : Copy MongoDB download package into rootMongoDB folder and unzip. then go to bin folder of MongoDB package and type commands ./mongod this will start main MongoDB database process. email: parkhekishor@gmail.com Mobile No. +919595745346
  • 7. Step 1.4: Connect to MongoDB using mongo.exe Open another command prompt and issue the following commands [root@HMCLUSTER2 /]# cd mongodb-linux-x86_64-2.0.6/bin [root@HMCLUSTER2 bin]# ./mongo mongo.rpm will connect mongod.rpm running on local host interface on 27017 port . you can check http services at http://localhost:28017 Step 1.5: test database and retrieve records. Type following commands in mongo shell >db.test.save ( , a : “test”- ) >db.test.find() { "_id" : ObjectId("50f8f47dc49f1d211f947d60"), "a" : "test" } > email: parkhekishor@gmail.com Mobile No. +919595745346
  • 8. Connecting to Database 1. From command prompt start mongo. By default mongo look for database server on local host on the port 27017. 2. To connect server on different port or interface use the --port and --host 3. Select data base use command db, it show name of current database. 4. To list all database use command in mongo shell show dbs. 5. Switch to new database name mydb with following operation use db name 6. Show mongo help in mongo shell using following operation help email: parkhekishor@gmail.com Mobile No. +919595745346
  • 9. Create collection and insert Documents 1. Switch to mydb with following operation use mydb 2. Create two document name doc1 and doc2 using JavaScript operation doc1 = ,name : “mongo” - doc2 = {x: 1} 3. Insert two document into collection say blog with following operation db.blog.insert( doc1) db.blog.insert( doc2) when you insert document then MongoDB create both database mydb and blog collection. 4. Confirm that collection is exist with following commands, show collections 5. Conform that document insert in collection using find () methods db.blog.find(); 6. Inserting multiple documents using for loop. email: parkhekishor@gmail.com Mobile No. +919595745346
  • 10. Implementing Curser 1. When you querying, MongoDB return curser object that contain result of query. 2. Iterating over the curser with loop var curser= db.blog.find(); while( curser.hasnext() ){ printjson( curser.next() ); } 3. Use array operation with curser curser[4]; email: parkhekishor@gmail.com Mobile No. +919595745346
  • 11. Querying for Specific Documents 1. define query q=, Field : “condition” - By passing this query document as parameter to find() method. db.blog.find(q) or db.blog.find( , field : “condition” - ) 2. Query and Projection e.g. doc1= , id : 1, name : “mongo” - to find all docs where id has a value 1 but return only name. query = { id : 1 } and projection = { name : 1} db.blog.find(query, projection) MongoDB return the following result, ,name : “mongo” - 3. Limiting number of document in result set db.blog.find().limit(3) email: parkhekishor@gmail.com Mobile No. +919595745346
  • 12. Core MongoDB Operation 1. Create 2. Read 3. Update 4. Delete Restriction on document _id field must be unique in collection The field name can not start with the $ character The field name can not start with the . Character 1 Create 1.1 insert and bulk insert 1.2 create with save 1.3 create with upsert email: parkhekishor@gmail.com Mobile No. +919595745346
  • 13. 2 Read operation 2.1 find 2.2 findOne 2.3 projection 3 Update 3.1 update field ($set) 3.2 update array ($push) 3.3 update and upsert (true or 1) 3.4 update multiple matching documents 4 DELETE 4.1 remove collection 4.2 remove matching documents 4.3 remove single matching documents email: parkhekishor@gmail.com Mobile No. +919595745346
  • 14. Querying 1. Specifying which query return Example consider following document, , id : ObjetcId(….), name : Ram, age : 16, email : ram@gmail.com, city : pune, pin : 413710 } email: parkhekishor@gmail.com Mobile No. +919595745346
  • 15. 1. You have user collection, if you are interested only in name and email fields, > db.user.find (, -, , “name” : 1, “email “: 1- ) Out put { “_id” : (…), name : “ram”, email : ram@gmail.com } 2. Conditional Query > db.user.find ( , “name” : “ram” - ) Out put , id : ObjetcId(….), name : Ram, age : 16, email : ram@gmail.com, city : pune, pin : 413710 } email: parkhekishor@gmail.com Mobile No. +919595745346
  • 16. 3 . Query Conditionals “$lt” = “<“ “$gt” =“>” “$lte” =“<=“ “$gte”=“>=“ are all comparison operators. > db.user.find(, “age” : ,$gt : 10- -) It gives all which has age greater than 10. >db.user.find(, “age” : ,$gt : 10 ,$lt : 50- -) it return all documents, field age in 10 to 50 range. > db.user.find ({"name" : { "$ne" : "ram" } }) Out put { "_id" : ObjectId("50ff718bc5d2a43b68806826"), "name" : "ram1", "email" : "ram@gmail.com", "id" : "10" } email: parkhekishor@gmail.com Mobile No. +919595745346
  • 17. 4. OR Queries There are two way to do OR query in MongoDB 4.1 “$in” If you have more than one possible value to match for a single key, then use array criteria > db.user.find (,"name" : , "$in" : *“ram”, “ram1” + - -) opposite of “$in” is “$nin” which return all documents that don’t match any of criteria. 4.2 “$or” >db.user.find(,"$or" : *,“name" : “ram” -, ,“age" : 10-+-) this query return all documents that satisfy either name or age criteria. 4.3 “$and” by using “AND” query you can narrow result set. >db.user.find(,"$and" : *,“name" : “ram” -, ,“age" : 10-+-) email: parkhekishor@gmail.com Mobile No. +919595745346
  • 18. 4.4 “$not” > db.user.find({".id1" : {$not :{$gt: 11}} }) { "_id" : ObjectId("50ff6950c5d2a43b68806825"), { "name" : "ram", "email" : "ram@gmail.com", "id" : "10" } { "_id" : ObjectId("50ff718bc5d2a43b68806826"), "name" : "ram1", "email" : "ram@gmail.com", "id" : "10" } { "_id" : ObjectId("50ff7efdc5d2a43b68806827"), "name" : "ram1", "email" : "ram@gmail.com", "id1" : 10 } 4.5 Regular expression Regular expressions are flexible for string matching. > db.user.find({"name" : /ram/i -) ‘i ‘ use for case - insensitive. email: parkhekishor@gmail.com Mobile No. +919595745346
  • 19. Querying Array Example suppose array is a list of colors, 1 like this: > db.user.insert({colors : [ "red" , "white" ,"green", "black"]}) the following query: > db.user.find({colors : "red"}) Out put: { "_id" : ObjectId("50ff83f9c5d2a43b68806829"), "colors" : [ "red", "white", "green", "black" ] } 2 if you need to match array more than on element the you use $all, > db.user.find(,colors : ,$all : *"red“ , “ black " +--) { "_id" : ObjectId("50ff83f9c5d2a43b68806829"), "colors" : [ "red", "white", "green", "black" ] } email: parkhekishor@gmail.com Mobile No. +919595745346
  • 20. 3 “$size” this operator allow you query to array of given size. >db.user.find ( { colors : {$size : 3} ) this can’t be combine with another $ conditional operator (like $gt ). 4 “$slice” The special "$slice" operator can be used to return a subset of elements for an array key. for example we had a blog post collection and we wanted first 10 comments. >db.blog.posts.findOne(criteria, {"comments" : {"$slice" : 10}}) Alternatively you find last 10 comments >db.blog.posts.findOne(criteria, {"comments" : {"$slice" : -10}}) email: parkhekishor@gmail.com Mobile No. +919595745346
  • 21. "$slice" can also return pages in the middle of the results by taking an offset and the number of elements to return: > db.blog.posts.findOne(criteria, {"comments" : {"$slice" : [23, 10]}}) this would keep first 23 elements and return 24th to 34th. email: parkhekishor@gmail.com Mobile No. +919595745346
  • 22. Querying Embedded Documents There are two ways querying embedded documents 1 Query for whole document 2 Query for individual document Example : { name : { first : “ram” , last : “roy” } } First query for whole document > db.user.find(, name : name : , first : “ram” ,last : “sharma” - - email: parkhekishor@gmail.com Mobile No. +919595745346
  • 23. Query for just a specific key or keys of an embedded document. >db.user.find( , “name.first” : “ram”-) Example { "content" : “what is MongoDB? ", "comments" : [ { "author" : “ram", "score" : 3, "comment" : "nice post" }, { "author" : “sham", "score" : 6, "comment" : "terrible post" } ] } email: parkhekishor@gmail.com Mobile No. +919595745346
  • 24. Complex query To find documents comments by ram, issue following commands, >db.user.find(, comments : , author : “ram” - -) alternatively >db.user.find(, “comments.author” : “ram” -) email: parkhekishor@gmail.com Mobile No. +919595745346