SlideShare a Scribd company logo
Java DevelopmentGo.. Go… JVM!
Library ChoicesRaw MongoDB DriverMap<String, Object> view of objectsRough but dynamicMorphia (type-safe mapper)POJOsAnnotation based (similar to JPA)Syntactic sugar and helpersOthersCode generators, other jvm languages
MongoDB Java DriverBSON PackageTypesEncode/DecodeDBObject (Map<String, Object>)Nested MapsDirectly encoded to binary format (BSON)MongoDB PackageMongoDBObject (BasicDBObject/Builder)DB/DBColletionDBQuery/DBCursor
BSON PackageTypesint and longArray/ArrayListStringbyte[] – binDataDouble (IEEE 754 FP)Date (secs since epoch)NullBooleanJavaScript StringRegex
MongoDB PackageMongoConnection, ThreadSafeWriteConcern*DBAuth, Collections getLastError()Command(), eval()RequestStart/DoneDBCollectionInsert/Save/Find/Remove/Update/FindAndModifyensureIndex
Simple ExampleDBCollectioncoll = new Mongo().getDB(“test”);coll.save(	new BasicDBObjectBuilder(“name”, “scott”).		append(“sex”, “male”).			append(“height”, 178)).get());
Simple Example, AgainDBCollectioncoll = new Mongo().getDB(“test”);Map<String, Object> fields = new …fields.add(“name”, “scott”); fields.add(“sex”, “male”);fields.add(“height”, 178);coll.insert(new BasicDBObject(fields));
DBObject <-> (B/J)SON{name:”scott”, sex:“male”, height: 178 }new BasicDBObjectBuilder().append(“name”, “scott”) .append(“sex”, “male”) .append(“height”, 178) .get();String name = (String)dbObj.get(“name”);
JSON.parse(…)DBObjectdbObj = JSON.parse(“	{‘name’:’scott’,‘height’: 178, ‘sex’:’male’}”);
ListsDBObjectdbObj = JSON.parse(“	{‘name’:’scott’,height: 178, sex:’male’}”);List<String> activities = new …activities.add(“mongodb”);activities.add(“java”);dbObj.put(“activities”, activities);{…, activities: [‘mongodb’, ‘java’]}
Maps of MapsCan represent object graph/treeAlways keyed off String (field)
Morphia: MongoDB MapperMaps POJOType-safeAccess Patterns: DAO/Datastore/???Data TypesPerforms wellJPA likeMany concepts came from Objectify (GAE)
Annotations@Entity(“collectionName”)@Id@Transient (not transient)@Indexed(…)@Property(“fieldAlias”)@AlsoLoad({aliases})@Reference@Serialized[@Embedded]
Lifecycle Events@PrePersist@PreSave@PostPersist@PreLoad@PostLoadEntityListenersEntityInterceptor
Basic POJO@Entityclass Person {@Id  String name;SexEnum sex;@Indexed  Integer height;}
Datastore Basicsget(class, id)find(class, […])save(entity, […])delete(query)getCount(query)update/First(query, upOps)findAndModify/Delete(query, upOps)
Add, Get, DeletePerson me = new Person(“scott”, Sex.Male, 179)Datastoreds = new Morphia().createDatastore()ds.save(me);Person meAgain = ds.get(Person.class, “scott”)ds.delete(me);
QueriesDatastoreds = …Query q = ds.createQuery(Person.class);q.field(“height”).greaterThan(155).limit(5);for(Person p : q.fetch())   print(p);Person me = q.field(“name”).startsWith(“sc”).get();
UpdateDatastoreds = …Query q = ds.find(Person.class, “name”, “scott”);UpdateOperationuo = ds.createUpdateOperations(cls)uo.set(“city”, “seattle”).set(“lastUpdated”, new Date());UpdateResults res = ds.update(q, uo);if(res.getUpdatedCount() > 0)  //do something?
Update Operationsset(field, val)unset(field)inc(field, [val])dec(field)add(field, val)addAdd(field, vals)removeFirst/Last(field)removeAll(field, vals)
Relationships[@Embedded]Loaded/Saved with EntityUpdate@ReferenceStored as DBRef(s)Loaded with EntityNot automatically savedKey<T> (DBRef)Stored as DBRef(s)Just a link, but resolvable by Datastore/Query
Questions?Look around…ScottHernandez@gmail.com

More Related Content

What's hot (19)

PPT
Mongo-Drupal
Forest Mars
 
ODP
DrupalCon Chicago Practical MongoDB and Drupal
Doug Green
 
PDF
The emerging world of mongo db csp
Carlos Sánchez Pérez
 
PDF
Indexing
Mike Dirolf
 
PPTX
Spring Data, Jongo & Co.
Tobias Trelle
 
PDF
Data access 2.0? Please welcome: Spring Data!
Oliver Gierke
 
PDF
ZendCon2010 Doctrine MongoDB ODM
Jonathan Wage
 
PDF
Doctrine MongoDB Object Document Mapper
Jonathan Wage
 
PDF
Building Apps with MongoDB
Nate Abele
 
PDF
Symfony Day 2010 Doctrine MongoDB ODM
Jonathan Wage
 
PDF
Symfony2 from the Trenches
Jonathan Wage
 
PDF
An introduction to MongoDB
Universidade de São Paulo
 
PDF
What do you mean, Backwards Compatibility?
Trisha Gee
 
PDF
Map/Confused? A practical approach to Map/Reduce with MongoDB
Uwe Printz
 
KEY
An introduction to CouchDB
David Coallier
 
PDF
Webinar: Building Your First App with MongoDB and Java
MongoDB
 
PPTX
Benefits of Using MongoDB Over RDBMS (At An Evening with MongoDB Minneapolis ...
MongoDB
 
ODP
This upload requires better support for ODP format
Forest Mars
 
PPS
MongoDB crud
Darshan Jayarama
 
Mongo-Drupal
Forest Mars
 
DrupalCon Chicago Practical MongoDB and Drupal
Doug Green
 
The emerging world of mongo db csp
Carlos Sánchez Pérez
 
Indexing
Mike Dirolf
 
Spring Data, Jongo & Co.
Tobias Trelle
 
Data access 2.0? Please welcome: Spring Data!
Oliver Gierke
 
ZendCon2010 Doctrine MongoDB ODM
Jonathan Wage
 
Doctrine MongoDB Object Document Mapper
Jonathan Wage
 
Building Apps with MongoDB
Nate Abele
 
Symfony Day 2010 Doctrine MongoDB ODM
Jonathan Wage
 
Symfony2 from the Trenches
Jonathan Wage
 
An introduction to MongoDB
Universidade de São Paulo
 
What do you mean, Backwards Compatibility?
Trisha Gee
 
Map/Confused? A practical approach to Map/Reduce with MongoDB
Uwe Printz
 
An introduction to CouchDB
David Coallier
 
Webinar: Building Your First App with MongoDB and Java
MongoDB
 
Benefits of Using MongoDB Over RDBMS (At An Evening with MongoDB Minneapolis ...
MongoDB
 
This upload requires better support for ODP format
Forest Mars
 
MongoDB crud
Darshan Jayarama
 

Similar to Java Development with MongoDB (20)

PPTX
Mongo sf easy java persistence
Scott Hernandez
 
PPTX
MongoDB Aug2010 SF Meetup
Scott Hernandez
 
PPT
Java Development with MongoDB (James Williams)
MongoSF
 
PPTX
mongodb introduction11111111111111111111
VADAPALLYPRAVEENKUMA1
 
PPTX
BedCon 2013 - Java Persistenz-Frameworks für MongoDB
Tobias Trelle
 
PDF
Getting Started with MongoDB (TCF ITPC 2014)
Michael Redlich
 
PPTX
Mongo+java (1)
MongoDB
 
PDF
Joker'15 Java straitjackets for MongoDB
Alexey Zinoviev
 
PDF
Getting Started with MongoDB
Michael Redlich
 
PDF
MongodB Internals
Norberto Leite
 
PPTX
MongoDB Introduction, Installation & Execution
iFour Technolab Pvt. Ltd.
 
PPTX
24-NoSQL continued.pptx
ssuser5c8249
 
PDF
An introduction into Spring Data
Oliver Gierke
 
PPTX
Kalp Corporate MongoDB Tutorials
Kalp Corporate
 
PPTX
Introduction to MongoDB
S.Shayan Daneshvar
 
PDF
Getting started with MongoDB and Scala - Open Source Bridge 2012
sullis
 
PDF
Mongo db basics
Claudio Montoya
 
PDF
Introduction to MongoDB Basics from SQL to NoSQL
Mayur Patil
 
PDF
San Francisco Java User Group
kchodorow
 
PPTX
MongoDB.pptx
Aayush Chimaniya
 
Mongo sf easy java persistence
Scott Hernandez
 
MongoDB Aug2010 SF Meetup
Scott Hernandez
 
Java Development with MongoDB (James Williams)
MongoSF
 
mongodb introduction11111111111111111111
VADAPALLYPRAVEENKUMA1
 
BedCon 2013 - Java Persistenz-Frameworks für MongoDB
Tobias Trelle
 
Getting Started with MongoDB (TCF ITPC 2014)
Michael Redlich
 
Mongo+java (1)
MongoDB
 
Joker'15 Java straitjackets for MongoDB
Alexey Zinoviev
 
Getting Started with MongoDB
Michael Redlich
 
MongodB Internals
Norberto Leite
 
MongoDB Introduction, Installation & Execution
iFour Technolab Pvt. Ltd.
 
24-NoSQL continued.pptx
ssuser5c8249
 
An introduction into Spring Data
Oliver Gierke
 
Kalp Corporate MongoDB Tutorials
Kalp Corporate
 
Introduction to MongoDB
S.Shayan Daneshvar
 
Getting started with MongoDB and Scala - Open Source Bridge 2012
sullis
 
Mongo db basics
Claudio Montoya
 
Introduction to MongoDB Basics from SQL to NoSQL
Mayur Patil
 
San Francisco Java User Group
kchodorow
 
MongoDB.pptx
Aayush Chimaniya
 
Ad

More from Scott Hernandez (11)

PPTX
MongoDB 2.8 Replication Internals: Fitting it all together
Scott Hernandez
 
PDF
Advanced Replication Internals
Scott Hernandez
 
PPTX
Realtime Analytics with MongoDB Counters (mongonyc 2012)
Scott Hernandez
 
PDF
MongoDB Operational Best Practices (mongosf2012)
Scott Hernandez
 
PDF
MongoDB Datacenter Awareness (mongosf2012)
Scott Hernandez
 
PPTX
MongoDB: Mastering the shell
Scott Hernandez
 
PPTX
MongoDB: Backup, Restore, and DR
Scott Hernandez
 
PPT
A Brief MongoDB Intro
Scott Hernandez
 
PPTX
What's new in the MongoDB Java Driver (2.5)?
Scott Hernandez
 
PPTX
MongoDB: tips, trick and hacks
Scott Hernandez
 
PPTX
Mastering the MongoDB Javascript Shell
Scott Hernandez
 
MongoDB 2.8 Replication Internals: Fitting it all together
Scott Hernandez
 
Advanced Replication Internals
Scott Hernandez
 
Realtime Analytics with MongoDB Counters (mongonyc 2012)
Scott Hernandez
 
MongoDB Operational Best Practices (mongosf2012)
Scott Hernandez
 
MongoDB Datacenter Awareness (mongosf2012)
Scott Hernandez
 
MongoDB: Mastering the shell
Scott Hernandez
 
MongoDB: Backup, Restore, and DR
Scott Hernandez
 
A Brief MongoDB Intro
Scott Hernandez
 
What's new in the MongoDB Java Driver (2.5)?
Scott Hernandez
 
MongoDB: tips, trick and hacks
Scott Hernandez
 
Mastering the MongoDB Javascript Shell
Scott Hernandez
 
Ad

Recently uploaded (20)

PDF
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
PPTX
Digital Circuits, important subject in CS
contactparinay1
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PPTX
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
PPT
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PDF
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
PDF
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
PPTX
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
PDF
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
Digital Circuits, important subject in CS
contactparinay1
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 

Java Development with MongoDB