SlideShare ist ein Scribd-Unternehmen logo
1 von 26
MongoDB using Grails Plugin
By Puneet Behl
MongoDB using Grails
Plugin
By Puneet Behl
Agenda
• Introduction to MongoDB
– Understanding collections, documents.
– Advantages of MongoDB over relational database.
• Getting familiar with the MongoDB console.
– Using selectors, inserts.
– Updating document & update modifiers.
– Upserts & Multiple Updates
– Mastering Find
• Integrating MongoDB with Grails using plug-in.
– Exploring plug-in features.
– Using Geospatial queries.
– Dynamic attributes.
– Using Low Level API.
Introduction to MongoDB
• MongoDB (from “humongous”) is an open-source document
database, and leading NoSQL database.
• Written in C++.
What is MongoDB?
• MongoDB is a document database that provides, high performance,
high availability, and easy scalability.
Why MongoDB?
“Show me your code and conceal your data structures, and I
shall continue to be mystified. Show me your data structures, and I
won’t usually need your code; it’ll be obvious.” - Eric Raymond,
in The Cathedral and the Bazaar, 1997”
Why MongoDB?
• Document Oriented Storage.
• Full Index Support.
• Replication & High Availability.
• Auto-Sharding.
• Querying.
• Fast In-Place Updates.
• Map/Reduce.
• GridFS.
• Professional Support By MongoDB.
Where MongoDB?
• Big Data.
• Content Management and Delivery.
• Mobile and Social Infrastructure.
• User Data Management.
• Data Hub.
Customers
Collections & Documents
• A MongoDB deployment hosts a number of databases. A database
holds a set of collections. A collection holds a set of documents. A
document is a set of key-value pairs. Documents have dynamic
schema. Dynamic schema means that documents in the same
collection do not need to have the same set of fields or structure, and
common fields in a collection’s documents may hold different types
of data.
Database
• A physical container for collections. Each database gets its own set
of files on the file system. A single MongoDB server typically has
multiple databases.
Collection
• A grouping of MongoDB documents. A collection is the equivalent of
an RDBMS table. A collection exists within a single database.
Collections do not enforce a schema. Documents within a collection
can have different fields. Typically, all documents in a collection have
a similar or related purpose.
Document
• A document is a set of key-value pairs. Documents have dynamic
schema. Dynamic schema means that documents in the same
collection do not need to have the same set of fields or structure, and
common fields in a collection’s documents may hold different types
of data.
Advantages of MongoDB over Relational
Databases
• Schema-less.
• Structure of a single object is clearer.
• No sql or hibernate queries (complex joins).
• Tuning
• Ease of scale-out
• Conversion  mapping of application objects to database objects not
needed.
• Uses internal memory for storing the (windowed) working set,
enabling faster access of data.
Getting Familiar with MongoDB console
• Start mongod server.
• db.help()
• db.stats()
• use <database-name>
• db.dropDatabase()
• db.getCollectionNames()
Commands:
• Insert
db.posts.insert({title: ‘MongoDB’, body: ‘I love MongoDB’, votes: 0})
• Find
db.posts.find() //List all posts
• Remove
db.posts.remove() //Remove all posts
Insert
db.posts.insert({
_id: ObjectId(-----(Timestamp),---(MachineID),--(ProcessID),---(Incrementer)) //Total 12(4 3 2 3) bytes,
may be displayed in hex
title: 'Big Data',
body 'Dummy description about Big Data',
tags: ['java', 'database', 'mongoDB', 'NoSQL'],
votes: 100,
comments: [
{
by:'XYZ',
text: 'Test comment 1',
dateCreated: new Date(2013,2,25,6,45),
votes: 0
},
{
by:'ABC',
text: 'Test comment 2',
dateCreated: new Date(2013,2,25,7,45),
votes: 5
}
]
})
Special Operations
• $lt : Less than
• $lte: Less than Equals
• $gt: Greater than
• $gte: Greater than Equals
• $ne: Not equals
• Examples:
– db.posts.find({tags: ‘java’,votes: {$gt:50}}
– db.posts.find({title:{$ne: ‘Java’}, votes:{$gt:50}})
– db.posts.find({date:{$exists: true}})
AND, OR
• {field1: value1, field2: value2} (AND statement)
• $or: {field1: value1, field2:value2}
• Examples:
– db.posts.find({title: {$ne:’Windows’}, votes: {$gte:100}})
– db.posts.find(votes: {$gt:1000}, $or: [{tags: ‘java’}, {tags: ‘sun’}] })
Update & Update Modifiers
• In the simplest form, update take 2 arguments: the selector (where)
to use and what field to update with.
• db.posts.update({title: ‘Big Data’},{‘votes’: 10000})
• db.posts.find({title:’Big Data’})
• db.posts.update({title:’Big Data’}, {$set: {tags: [‘MongoDB’, ’10gen’]}})
• db.posts.update({title: ‘Big Data’}, {$inc:{votes:-10}})
• db.posts.update({title: ‘Big Data’}, {$push: {tags:’NoSQL’}})
Upserts
• An upsert updates the document if found or insert it if not. Upserts
are handy to have in certain situations. To enable upserting set third
parameter to true.
• A mundane example for upsert is a hit counter for website. For
example:
– db.posts.update({title: ‘Test’}, {$inc: {hits: 1}})
– db.posts.find({title: ‘Test’},{hits:1,’_id’:0})
– db.posts.update({title: ‘Test’}, {$inc: {hits: 1}}, true)
– db.posts.find({title: ‘Test’},{hits:1,’_id’:0})
Multiple Updates
• For multiple updates, a fourth parameter must be set to true
• db.posts.update({},{$inc: {votes: 10}}
• db.posts.find()
• db.posts.update({}.{$inc:{votes:10}}, false, true)
Mastering Find
• Field Selection
• Ordering
• Paging
• Count
Field Selection
• Find takes a second optional parameter. This parameter is the list of
fields we want to retrieve
• By default _id field is always returned. We can explicitly exclude it.
• Example: {name: 1. _id: 0}
1 for including and 0 for excluding the field.
Ordering
• Find returns a cursor whose execution is delayed until needed.
• We can chain sort method to find.
• Sort works a lot like field selection.
• Use 1 for ascending and -1 for descending order.
• For example:
– db.posts.find({}).sort({title:1})
– db.posts.find().sort({title:1, votes:-1})
Paging
• Paging results can be accomplished via limit and skip cursor
methods.
• For example:
– To get the post having highest votes we could do:
• db.posts.find().sort({votes:-1}).limit(1)
– To get the post having second highest votes:
• db.posts.find().sort({votes:-1}).limit(2).skip(1)

Weitere ähnliche Inhalte

Was ist angesagt?

Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBRavi Teja
 
Mongodb - NoSql Database
Mongodb - NoSql DatabaseMongodb - NoSql Database
Mongodb - NoSql DatabasePrashant Gupta
 
How to leverage MongoDB for Big Data Analysis and Operations with MongoDB's A...
How to leverage MongoDB for Big Data Analysis and Operations with MongoDB's A...How to leverage MongoDB for Big Data Analysis and Operations with MongoDB's A...
How to leverage MongoDB for Big Data Analysis and Operations with MongoDB's A...Gianfranco Palumbo
 
Basics of MongoDB
Basics of MongoDB Basics of MongoDB
Basics of MongoDB Habilelabs
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBMike Dirolf
 
Social Data and Log Analysis Using MongoDB
Social Data and Log Analysis Using MongoDBSocial Data and Log Analysis Using MongoDB
Social Data and Log Analysis Using MongoDBTakahiro Inoue
 
The Basics of MongoDB
The Basics of MongoDBThe Basics of MongoDB
The Basics of MongoDBvaluebound
 
Mongodb basics and architecture
Mongodb basics and architectureMongodb basics and architecture
Mongodb basics and architectureBishal Khanal
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBJustin Smestad
 
MongoDB basics & Introduction
MongoDB basics & IntroductionMongoDB basics & Introduction
MongoDB basics & IntroductionJerwin Roy
 
MongoDB presentation
MongoDB presentationMongoDB presentation
MongoDB presentationHyphen Call
 
MongoDB Schema Design by Examples
MongoDB Schema Design by ExamplesMongoDB Schema Design by Examples
MongoDB Schema Design by ExamplesHadi Ariawan
 
Mongodb intro
Mongodb introMongodb intro
Mongodb introchristkv
 

Was ist angesagt? (20)

MongoDB
MongoDBMongoDB
MongoDB
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Mongo DB 102
Mongo DB 102Mongo DB 102
Mongo DB 102
 
Mongo DB Presentation
Mongo DB PresentationMongo DB Presentation
Mongo DB Presentation
 
Mongodb - NoSql Database
Mongodb - NoSql DatabaseMongodb - NoSql Database
Mongodb - NoSql Database
 
MongoDB
MongoDBMongoDB
MongoDB
 
How to leverage MongoDB for Big Data Analysis and Operations with MongoDB's A...
How to leverage MongoDB for Big Data Analysis and Operations with MongoDB's A...How to leverage MongoDB for Big Data Analysis and Operations with MongoDB's A...
How to leverage MongoDB for Big Data Analysis and Operations with MongoDB's A...
 
Basics of MongoDB
Basics of MongoDB Basics of MongoDB
Basics of MongoDB
 
Mongo db1
Mongo db1Mongo db1
Mongo db1
 
MongoDB 101
MongoDB 101MongoDB 101
MongoDB 101
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Mongo db basics
Mongo db basicsMongo db basics
Mongo db basics
 
Social Data and Log Analysis Using MongoDB
Social Data and Log Analysis Using MongoDBSocial Data and Log Analysis Using MongoDB
Social Data and Log Analysis Using MongoDB
 
The Basics of MongoDB
The Basics of MongoDBThe Basics of MongoDB
The Basics of MongoDB
 
Mongodb basics and architecture
Mongodb basics and architectureMongodb basics and architecture
Mongodb basics and architecture
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
MongoDB basics & Introduction
MongoDB basics & IntroductionMongoDB basics & Introduction
MongoDB basics & Introduction
 
MongoDB presentation
MongoDB presentationMongoDB presentation
MongoDB presentation
 
MongoDB Schema Design by Examples
MongoDB Schema Design by ExamplesMongoDB Schema Design by Examples
MongoDB Schema Design by Examples
 
Mongodb intro
Mongodb introMongodb intro
Mongodb intro
 

Andere mochten auch

Sanat
SanatSanat
Sanatmerve
 
Eloy alfaro high school
Eloy alfaro high schoolEloy alfaro high school
Eloy alfaro high schoolANA MENDOZA
 
2014: When Digital Marketing moves from Hype to Reality
2014: When Digital Marketing moves from Hype to Reality2014: When Digital Marketing moves from Hype to Reality
2014: When Digital Marketing moves from Hype to RealityJohn Watton
 
소통PT - 2010 서울시대안교육센터 교사워크숍
소통PT - 2010 서울시대안교육센터 교사워크숍소통PT - 2010 서울시대안교육센터 교사워크숍
소통PT - 2010 서울시대안교육센터 교사워크숍NaYoun Kim
 
Production schedule 2011
Production schedule 2011Production schedule 2011
Production schedule 2011sathma
 
Reinventing Marketing in the Age of Digital
Reinventing Marketing in the Age of DigitalReinventing Marketing in the Age of Digital
Reinventing Marketing in the Age of DigitalJohn Watton
 
Job summary
Job summaryJob summary
Job summarysathma
 
Interactive dia3 (dl3) holsten english translation
Interactive dia3 (dl3) holsten english translationInteractive dia3 (dl3) holsten english translation
Interactive dia3 (dl3) holsten english translationKonstellation
 
FUKUYAMA BASE Workshop Vol.10 Theme
FUKUYAMA BASE Workshop Vol.10 ThemeFUKUYAMA BASE Workshop Vol.10 Theme
FUKUYAMA BASE Workshop Vol.10 Themenoteproject
 
Fukuyama Base Workshop Vol07 theme
Fukuyama Base Workshop Vol07 themeFukuyama Base Workshop Vol07 theme
Fukuyama Base Workshop Vol07 themenoteproject
 
Nurturing: Where Human Touch & Digital Practices come together
Nurturing: Where Human Touch & Digital Practices come togetherNurturing: Where Human Touch & Digital Practices come together
Nurturing: Where Human Touch & Digital Practices come togetherJohn Watton
 
Social Media & de (onderwijs) praktijk
Social Media & de (onderwijs) praktijkSocial Media & de (onderwijs) praktijk
Social Media & de (onderwijs) praktijkIT-Workz
 
FUKUYAMA BASE Workshop Vol.09 Theme
FUKUYAMA BASE Workshop Vol.09 ThemeFUKUYAMA BASE Workshop Vol.09 Theme
FUKUYAMA BASE Workshop Vol.09 Themenoteproject
 
FUKUYAMA BASE WORKSHOP Vol11 Theme
FUKUYAMA BASE WORKSHOP Vol11 ThemeFUKUYAMA BASE WORKSHOP Vol11 Theme
FUKUYAMA BASE WORKSHOP Vol11 Themenoteproject
 
Open day presentation 2
Open day presentation 2Open day presentation 2
Open day presentation 2sallyross
 
2010 SMX Advanced - Advanced CRO Beyond the Landing Page
2010 SMX Advanced - Advanced CRO Beyond the Landing Page2010 SMX Advanced - Advanced CRO Beyond the Landing Page
2010 SMX Advanced - Advanced CRO Beyond the Landing PageVertster.com
 
SC PBA 2010-2011 nominees
SC PBA 2010-2011 nomineesSC PBA 2010-2011 nominees
SC PBA 2010-2011 nomineesSharon Matney
 

Andere mochten auch (20)

Sanat
SanatSanat
Sanat
 
Eloy alfaro high school
Eloy alfaro high schoolEloy alfaro high school
Eloy alfaro high school
 
Big Data Expertise
Big Data ExpertiseBig Data Expertise
Big Data Expertise
 
Getting groovier-with-vertx
Getting groovier-with-vertxGetting groovier-with-vertx
Getting groovier-with-vertx
 
2014: When Digital Marketing moves from Hype to Reality
2014: When Digital Marketing moves from Hype to Reality2014: When Digital Marketing moves from Hype to Reality
2014: When Digital Marketing moves from Hype to Reality
 
소통PT - 2010 서울시대안교육센터 교사워크숍
소통PT - 2010 서울시대안교육센터 교사워크숍소통PT - 2010 서울시대안교육센터 교사워크숍
소통PT - 2010 서울시대안교육센터 교사워크숍
 
Production schedule 2011
Production schedule 2011Production schedule 2011
Production schedule 2011
 
Reinventing Marketing in the Age of Digital
Reinventing Marketing in the Age of DigitalReinventing Marketing in the Age of Digital
Reinventing Marketing in the Age of Digital
 
Job summary
Job summaryJob summary
Job summary
 
Interactive dia3 (dl3) holsten english translation
Interactive dia3 (dl3) holsten english translationInteractive dia3 (dl3) holsten english translation
Interactive dia3 (dl3) holsten english translation
 
FUKUYAMA BASE Workshop Vol.10 Theme
FUKUYAMA BASE Workshop Vol.10 ThemeFUKUYAMA BASE Workshop Vol.10 Theme
FUKUYAMA BASE Workshop Vol.10 Theme
 
Fukuyama Base Workshop Vol07 theme
Fukuyama Base Workshop Vol07 themeFukuyama Base Workshop Vol07 theme
Fukuyama Base Workshop Vol07 theme
 
Nurturing: Where Human Touch & Digital Practices come together
Nurturing: Where Human Touch & Digital Practices come togetherNurturing: Where Human Touch & Digital Practices come together
Nurturing: Where Human Touch & Digital Practices come together
 
Social Media & de (onderwijs) praktijk
Social Media & de (onderwijs) praktijkSocial Media & de (onderwijs) praktijk
Social Media & de (onderwijs) praktijk
 
FUKUYAMA BASE Workshop Vol.09 Theme
FUKUYAMA BASE Workshop Vol.09 ThemeFUKUYAMA BASE Workshop Vol.09 Theme
FUKUYAMA BASE Workshop Vol.09 Theme
 
FUKUYAMA BASE WORKSHOP Vol11 Theme
FUKUYAMA BASE WORKSHOP Vol11 ThemeFUKUYAMA BASE WORKSHOP Vol11 Theme
FUKUYAMA BASE WORKSHOP Vol11 Theme
 
Open day presentation 2
Open day presentation 2Open day presentation 2
Open day presentation 2
 
Object Oriented JavaScript - II
Object Oriented JavaScript - IIObject Oriented JavaScript - II
Object Oriented JavaScript - II
 
2010 SMX Advanced - Advanced CRO Beyond the Landing Page
2010 SMX Advanced - Advanced CRO Beyond the Landing Page2010 SMX Advanced - Advanced CRO Beyond the Landing Page
2010 SMX Advanced - Advanced CRO Beyond the Landing Page
 
SC PBA 2010-2011 nominees
SC PBA 2010-2011 nomineesSC PBA 2010-2011 nominees
SC PBA 2010-2011 nominees
 

Ähnlich wie MongoDB using Grails plugin by puneet behl

MongoDB NoSQL database a deep dive -MyWhitePaper
MongoDB  NoSQL database a deep dive -MyWhitePaperMongoDB  NoSQL database a deep dive -MyWhitePaper
MongoDB NoSQL database a deep dive -MyWhitePaperRajesh Kumar
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBRaghunath A
 
Mongo Bb - NoSQL tutorial
Mongo Bb - NoSQL tutorialMongo Bb - NoSQL tutorial
Mongo Bb - NoSQL tutorialMohan Rathour
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBSean Laurent
 
Introduction to MongoDB and its best practices
Introduction to MongoDB and its best practicesIntroduction to MongoDB and its best practices
Introduction to MongoDB and its best practicesAshishRathore72
 
Webinar: What's new in the .NET Driver
Webinar: What's new in the .NET DriverWebinar: What's new in the .NET Driver
Webinar: What's new in the .NET DriverMongoDB
 
Introduction To MongoDB
Introduction To MongoDBIntroduction To MongoDB
Introduction To MongoDBElieHannouch
 
A Presentation on MongoDB Introduction - Habilelabs
A Presentation on MongoDB Introduction - HabilelabsA Presentation on MongoDB Introduction - Habilelabs
A Presentation on MongoDB Introduction - HabilelabsHabilelabs
 
MongoDB: a gentle, friendly overview
MongoDB: a gentle, friendly overviewMongoDB: a gentle, friendly overview
MongoDB: a gentle, friendly overviewAntonio Pintus
 
9. Document Oriented Databases
9. Document Oriented Databases9. Document Oriented Databases
9. Document Oriented DatabasesFabio Fumarola
 

Ähnlich wie MongoDB using Grails plugin by puneet behl (20)

MongoDB_ppt.pptx
MongoDB_ppt.pptxMongoDB_ppt.pptx
MongoDB_ppt.pptx
 
Mongo db
Mongo dbMongo db
Mongo db
 
MongoDB NoSQL database a deep dive -MyWhitePaper
MongoDB  NoSQL database a deep dive -MyWhitePaperMongoDB  NoSQL database a deep dive -MyWhitePaper
MongoDB NoSQL database a deep dive -MyWhitePaper
 
MongoDB
MongoDBMongoDB
MongoDB
 
Mongodb
MongodbMongodb
Mongodb
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
fard car.pptx
fard car.pptxfard car.pptx
fard car.pptx
 
Mongo Bb - NoSQL tutorial
Mongo Bb - NoSQL tutorialMongo Bb - NoSQL tutorial
Mongo Bb - NoSQL tutorial
 
MongoDB
MongoDBMongoDB
MongoDB
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Introduction to MongoDB and its best practices
Introduction to MongoDB and its best practicesIntroduction to MongoDB and its best practices
Introduction to MongoDB and its best practices
 
Webinar: What's new in the .NET Driver
Webinar: What's new in the .NET DriverWebinar: What's new in the .NET Driver
Webinar: What's new in the .NET Driver
 
MongoDb and NoSQL
MongoDb and NoSQLMongoDb and NoSQL
MongoDb and NoSQL
 
No sq lv1_0
No sq lv1_0No sq lv1_0
No sq lv1_0
 
Mongo db nosql (1)
Mongo db nosql (1)Mongo db nosql (1)
Mongo db nosql (1)
 
Introduction To MongoDB
Introduction To MongoDBIntroduction To MongoDB
Introduction To MongoDB
 
A Presentation on MongoDB Introduction - Habilelabs
A Presentation on MongoDB Introduction - HabilelabsA Presentation on MongoDB Introduction - Habilelabs
A Presentation on MongoDB Introduction - Habilelabs
 
MongoDB: a gentle, friendly overview
MongoDB: a gentle, friendly overviewMongoDB: a gentle, friendly overview
MongoDB: a gentle, friendly overview
 
9. Document Oriented Databases
9. Document Oriented Databases9. Document Oriented Databases
9. Document Oriented Databases
 
MediaGlu and Mongo DB
MediaGlu and Mongo DBMediaGlu and Mongo DB
MediaGlu and Mongo DB
 

Mehr von TO THE NEW | Technology

10 Best Node.js Practices you Need to Know!
10 Best Node.js Practices you Need to Know!10 Best Node.js Practices you Need to Know!
10 Best Node.js Practices you Need to Know!TO THE NEW | Technology
 
10 Pragmatic UX techniques for building smarter products:
10 Pragmatic UX techniques for building smarter products:10 Pragmatic UX techniques for building smarter products:
10 Pragmatic UX techniques for building smarter products:TO THE NEW | Technology
 
12 Key points which make Swift more effective than Objective C
12 Key points which make Swift more effective than Objective C12 Key points which make Swift more effective than Objective C
12 Key points which make Swift more effective than Objective CTO THE NEW | Technology
 
An introduction to Object Oriented JavaScript
An introduction to Object Oriented JavaScriptAn introduction to Object Oriented JavaScript
An introduction to Object Oriented JavaScriptTO THE NEW | Technology
 
(AWS) Auto Scaling : Evening Session by Amazon and IntelliGrape Software
(AWS) Auto Scaling : Evening Session by Amazon and IntelliGrape Software(AWS) Auto Scaling : Evening Session by Amazon and IntelliGrape Software
(AWS) Auto Scaling : Evening Session by Amazon and IntelliGrape SoftwareTO THE NEW | Technology
 
BigData Search Simplified with ElasticSearch
BigData Search Simplified with ElasticSearchBigData Search Simplified with ElasticSearch
BigData Search Simplified with ElasticSearchTO THE NEW | Technology
 

Mehr von TO THE NEW | Technology (20)

10 Best Node.js Practices you Need to Know!
10 Best Node.js Practices you Need to Know!10 Best Node.js Practices you Need to Know!
10 Best Node.js Practices you Need to Know!
 
10 Pragmatic UX techniques for building smarter products:
10 Pragmatic UX techniques for building smarter products:10 Pragmatic UX techniques for building smarter products:
10 Pragmatic UX techniques for building smarter products:
 
12 Key points which make Swift more effective than Objective C
12 Key points which make Swift more effective than Objective C12 Key points which make Swift more effective than Objective C
12 Key points which make Swift more effective than Objective C
 
Gulp - The Streaming Build System
Gulp - The Streaming Build SystemGulp - The Streaming Build System
Gulp - The Streaming Build System
 
Grails Spring Boot
Grails Spring BootGrails Spring Boot
Grails Spring Boot
 
AWS Elastic Beanstalk
AWS Elastic BeanstalkAWS Elastic Beanstalk
AWS Elastic Beanstalk
 
Content migration to AEM
Content migration to AEMContent migration to AEM
Content migration to AEM
 
AWS CodeDeploy
AWS CodeDeployAWS CodeDeploy
AWS CodeDeploy
 
An introduction to Object Oriented JavaScript
An introduction to Object Oriented JavaScriptAn introduction to Object Oriented JavaScript
An introduction to Object Oriented JavaScript
 
(AWS) Auto Scaling : Evening Session by Amazon and IntelliGrape Software
(AWS) Auto Scaling : Evening Session by Amazon and IntelliGrape Software(AWS) Auto Scaling : Evening Session by Amazon and IntelliGrape Software
(AWS) Auto Scaling : Evening Session by Amazon and IntelliGrape Software
 
Cloud Formation
Cloud FormationCloud Formation
Cloud Formation
 
BigData Search Simplified with ElasticSearch
BigData Search Simplified with ElasticSearchBigData Search Simplified with ElasticSearch
BigData Search Simplified with ElasticSearch
 
JULY IN GRAILS
JULY IN GRAILSJULY IN GRAILS
JULY IN GRAILS
 
Grails Spock Testing
Grails Spock TestingGrails Spock Testing
Grails Spock Testing
 
Introduction to Kanban
Introduction to KanbanIntroduction to Kanban
Introduction to Kanban
 
Introduction to Heroku
Introduction to HerokuIntroduction to Heroku
Introduction to Heroku
 
Node JS
Node JSNode JS
Node JS
 
MongoDB (Advanced)
MongoDB (Advanced)MongoDB (Advanced)
MongoDB (Advanced)
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
 
Building blocks of e-commerce sites
Building blocks of e-commerce sitesBuilding blocks of e-commerce sites
Building blocks of e-commerce sites
 

Kürzlich hochgeladen

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfChris Hunter
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfSanaAli374401
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.MateoGardella
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 

Kürzlich hochgeladen (20)

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 

MongoDB using Grails plugin by puneet behl

  • 1. MongoDB using Grails Plugin By Puneet Behl
  • 3. Agenda • Introduction to MongoDB – Understanding collections, documents. – Advantages of MongoDB over relational database. • Getting familiar with the MongoDB console. – Using selectors, inserts. – Updating document & update modifiers. – Upserts & Multiple Updates – Mastering Find • Integrating MongoDB with Grails using plug-in. – Exploring plug-in features. – Using Geospatial queries. – Dynamic attributes. – Using Low Level API.
  • 4. Introduction to MongoDB • MongoDB (from “humongous”) is an open-source document database, and leading NoSQL database. • Written in C++.
  • 5. What is MongoDB? • MongoDB is a document database that provides, high performance, high availability, and easy scalability.
  • 6. Why MongoDB? “Show me your code and conceal your data structures, and I shall continue to be mystified. Show me your data structures, and I won’t usually need your code; it’ll be obvious.” - Eric Raymond, in The Cathedral and the Bazaar, 1997”
  • 7. Why MongoDB? • Document Oriented Storage. • Full Index Support. • Replication & High Availability. • Auto-Sharding. • Querying. • Fast In-Place Updates. • Map/Reduce. • GridFS. • Professional Support By MongoDB.
  • 8. Where MongoDB? • Big Data. • Content Management and Delivery. • Mobile and Social Infrastructure. • User Data Management. • Data Hub.
  • 10. Collections & Documents • A MongoDB deployment hosts a number of databases. A database holds a set of collections. A collection holds a set of documents. A document is a set of key-value pairs. Documents have dynamic schema. Dynamic schema means that documents in the same collection do not need to have the same set of fields or structure, and common fields in a collection’s documents may hold different types of data.
  • 11. Database • A physical container for collections. Each database gets its own set of files on the file system. A single MongoDB server typically has multiple databases.
  • 12. Collection • A grouping of MongoDB documents. A collection is the equivalent of an RDBMS table. A collection exists within a single database. Collections do not enforce a schema. Documents within a collection can have different fields. Typically, all documents in a collection have a similar or related purpose.
  • 13. Document • A document is a set of key-value pairs. Documents have dynamic schema. Dynamic schema means that documents in the same collection do not need to have the same set of fields or structure, and common fields in a collection’s documents may hold different types of data.
  • 14. Advantages of MongoDB over Relational Databases • Schema-less. • Structure of a single object is clearer. • No sql or hibernate queries (complex joins). • Tuning • Ease of scale-out • Conversion mapping of application objects to database objects not needed. • Uses internal memory for storing the (windowed) working set, enabling faster access of data.
  • 15. Getting Familiar with MongoDB console • Start mongod server. • db.help() • db.stats() • use <database-name> • db.dropDatabase() • db.getCollectionNames()
  • 16. Commands: • Insert db.posts.insert({title: ‘MongoDB’, body: ‘I love MongoDB’, votes: 0}) • Find db.posts.find() //List all posts • Remove db.posts.remove() //Remove all posts
  • 17. Insert db.posts.insert({ _id: ObjectId(-----(Timestamp),---(MachineID),--(ProcessID),---(Incrementer)) //Total 12(4 3 2 3) bytes, may be displayed in hex title: 'Big Data', body 'Dummy description about Big Data', tags: ['java', 'database', 'mongoDB', 'NoSQL'], votes: 100, comments: [ { by:'XYZ', text: 'Test comment 1', dateCreated: new Date(2013,2,25,6,45), votes: 0 }, { by:'ABC', text: 'Test comment 2', dateCreated: new Date(2013,2,25,7,45), votes: 5 } ] })
  • 18. Special Operations • $lt : Less than • $lte: Less than Equals • $gt: Greater than • $gte: Greater than Equals • $ne: Not equals • Examples: – db.posts.find({tags: ‘java’,votes: {$gt:50}} – db.posts.find({title:{$ne: ‘Java’}, votes:{$gt:50}}) – db.posts.find({date:{$exists: true}})
  • 19. AND, OR • {field1: value1, field2: value2} (AND statement) • $or: {field1: value1, field2:value2} • Examples: – db.posts.find({title: {$ne:’Windows’}, votes: {$gte:100}}) – db.posts.find(votes: {$gt:1000}, $or: [{tags: ‘java’}, {tags: ‘sun’}] })
  • 20. Update & Update Modifiers • In the simplest form, update take 2 arguments: the selector (where) to use and what field to update with. • db.posts.update({title: ‘Big Data’},{‘votes’: 10000}) • db.posts.find({title:’Big Data’}) • db.posts.update({title:’Big Data’}, {$set: {tags: [‘MongoDB’, ’10gen’]}}) • db.posts.update({title: ‘Big Data’}, {$inc:{votes:-10}}) • db.posts.update({title: ‘Big Data’}, {$push: {tags:’NoSQL’}})
  • 21. Upserts • An upsert updates the document if found or insert it if not. Upserts are handy to have in certain situations. To enable upserting set third parameter to true. • A mundane example for upsert is a hit counter for website. For example: – db.posts.update({title: ‘Test’}, {$inc: {hits: 1}}) – db.posts.find({title: ‘Test’},{hits:1,’_id’:0}) – db.posts.update({title: ‘Test’}, {$inc: {hits: 1}}, true) – db.posts.find({title: ‘Test’},{hits:1,’_id’:0})
  • 22. Multiple Updates • For multiple updates, a fourth parameter must be set to true • db.posts.update({},{$inc: {votes: 10}} • db.posts.find() • db.posts.update({}.{$inc:{votes:10}}, false, true)
  • 23. Mastering Find • Field Selection • Ordering • Paging • Count
  • 24. Field Selection • Find takes a second optional parameter. This parameter is the list of fields we want to retrieve • By default _id field is always returned. We can explicitly exclude it. • Example: {name: 1. _id: 0} 1 for including and 0 for excluding the field.
  • 25. Ordering • Find returns a cursor whose execution is delayed until needed. • We can chain sort method to find. • Sort works a lot like field selection. • Use 1 for ascending and -1 for descending order. • For example: – db.posts.find({}).sort({title:1}) – db.posts.find().sort({title:1, votes:-1})
  • 26. Paging • Paging results can be accomplished via limit and skip cursor methods. • For example: – To get the post having highest votes we could do: • db.posts.find().sort({votes:-1}).limit(1) – To get the post having second highest votes: • db.posts.find().sort({votes:-1}).limit(2).skip(1)