SlideShare une entreprise Scribd logo
1  sur  50
codecentric AG 1
Morphia, Spring Data & Co. -
Java Persistenz-Frameworks für MongoDB
Tobias.Trelle@codecentric.de @tobiastrelle
codecentric AG 2
Tobias Trelle
- Senior IT Consultant @
codecentric AG (Düsseldorf)
- Organisator MongoDB
Usergruppe Düsseldorf
- Autor MongoDB-Buch
(dpunkt-Verlag)
codecentric AG 3
Where have all my tables gone …
ORM is dead
long live ODM
codecentric AG 4
MongoDB?
 NoSQL-Datenbank / Open Source
 Dokumentenorientiert
 Hochperformant, horizontal skalierbar (scale-out)
 Replication & Sharding out-of-the-box
 Map/Reduce
 Geospatial Indexes / Queries
codecentric AG 5
Grundkonzept MongoDB-Server
Server
Database
Collection
Document
Field
Tabelle
Zeile
Spalte
Relationales
Pendant Aber …
Flexibles
Schema
- Arrays
- Rekursiv
codecentric AG 6
Document
{
title: „Praxisbuch Mongo“,
version: 0.1,
copies_sold: 0,
authors: [
{ name: „Uwe Seiler“,
email: „uwe.seiler@codecentric.de“ },
{ name: „Tobias Trelle“,
email: „tobias.trelle@codecentric.de“}
]
}
codecentric AG 7
JSON vs. BSON
{ hello: "MongoDB" }
x18x00x00x00
x02
hellox00
x08x00x00x00MongoDBx00
x00
codecentric AG 8
CRUD = IFUR
insert(…)
find(…), findOne(…)
update(…)
remove()
codecentric AG 9
Java Persistenz mit MongoDB
MongoDB Java Driver
Spring Data MongoDB
Morphia
Hibernate OGM
Jongo
codecentric AG 10
Use Case
db.order.find( {"items.quantity": ? } )
codecentric AG 11
Mongo Java Driver
codecentric AG 12
MongoDB Drivers
 One wire protocol for all client languages
 A driver implementation per language
 Responsibilities:
 Converting language dependent data structures   BSON
 Generating ObjectId for _id field
 Overview: http://www.mongodb.org/display/DOCS/Drivers
codecentric AG 13
MongoDB Java Driver
One JAR w/o further dependencies:
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>2.11.3</version>
</dependency>
github:
https://github.com/mongodb/mongo-java-driver
codecentric AG 14
Java Driver: Connect to MongoDB
import com.mongodb.MongoClient;
// Default: localhost:27017
mongo = new MongoClient();
// Sharding: mongos server
mongo = new MongoClient("mongos01", 4711);
// Replica set
mongo = new MongoClient(Arrays.asList(
new ServerAddress("replicant01", 10001),
new ServerAddress("replicant02", 10002),
new ServerAddress("replicant03", 10003)
));
codecentric AG 15
Java Driver: Database / Collection
import com.mongodb.DB;
import com.mongodb.DBCollection;
DB db = mongo.getDB("test");
DBCollection collection =
db.getCollection("foo");
codecentric AG 16
Java Driver: Documents
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
// insert document
DBObject doc = new BasicDBObject();
doc.put("date", new Date());
doc.put("i", 42);
collection.insert(doc);
codecentric AG 17
Java Driver: Queries
import com.mongodb.DBCursor;
DBCursor cursor;
cursor = collection.find(); // all documents
// documents w/ {i: 42}
cursor = collection.find(
new BasicDBObject("i", 42) );
document = cursor.next();
...
codecentric AG 18
Java Driver: Order Use Case
DB db = mongo.getDB("test");
DBCollection collection = db.getCollection("order");
DBObject order;
List<DBObject> items = new ArrayList<DBObject>();
DBObject item;
// order
order = new BasicDBObject();
order.put("date", new Date());
order.put("custInfo" , "Tobias Trelle");
order.put("items", items);
// items
item = new BasicDBObject();
item.put("quantity", 1);
item.put("price", 47.11);
item.put("desc", "Item #1");
items.add(item);
item = new BasicDBObject();
item.put("quantity", 2);
item.put("price", 42.0);
item.put("desc", "Item #2");
items.add(item);
collection.insert(order);
codecentric AG 19
Java Driver: Order Use Case
DB db = mongo.getDB("test");
DBCollection collection = db.getCollection("order");
DBObject query;
DBObject document;
DBCursor cursor;
query = new BasicDBObject("items.quantity", 2);
cursor = collection.find(query);
while ( cursor.hasNext() ) {
document = cursor.next();
println(document);
}
codecentric AG 20
Spring Data
MongoDB
codecentric AG 21
Spring Data MongoDB – Fact Sheet
Vendor VMware / SpringSource
License Apache License, Version 2.0
Documentation http://www.springsource.org/spring-data/mongodb
Main Features • Repository Support
• Object/Document Mapping
• Templating
codecentric AG 22
Spring Data
Common patterns for RDBMS and NoSQL data stores
Spring Data
RDBMS MongoDB Neo4j …
Spring Data
JPA
CrudRepository PagingAndSortingRepository
JpaRepository
JPA
JDBC
Spring Data
MongoDB
MongoRepository
MongoTemplate
Spring Data
Neo4j
Spring Data
…
GraphRepository
Neo4jTemplate
Mongo Java Driver
Embedded REST
Quelle: http://www.infoq.com/articles/spring-data-intro
codecentric AG 23
Spring Data MongoDB
Templating
 Resource abstraction
 Configure connections to mongod / mongos node(s)
 Collection lifecycle ( create, drop)
 Map/Reduce / Aggregation
Object Mapping
 Annotation based: @Document, @Field, @Index etc.
 Classes are mapped to collections, Java Objects to documents
Repository Support
 Queries are derived from methods signatures
 Annotated Queries
codecentric AG 24
Spring Data MongoDB: Configuration
<!-- Connection to MongoDB server -->
<mongo:db-factory host="localhost" port="27017" dbname="test" />
<!-- MongoDB Template -->
<bean id="mongoTemplate„
class="org.springframework.data.mongodb.core.MongoTemplate">
<constructor-arg name="mongoDbFactory" ref="mongoDbFactory"/>
</bean>
<!-- Package w/ automagic repositories -->
<mongo:repositories base-package="mongodb" />
codecentric AG 26
Spring Data MongoDB: Object Mapping
public class Order {
@Id private String id;
private Date date;
@Field("custInfo") private String customerInfo;
List<Item> items; ...
}
public class Item {
private int quantity;
private double price;
@Field("desc") private String description;
...
}
codecentric AG 27
Spring Data MongoDB: Repository Support
public interface OrderRepository extends
MongoRepository<Order, String> {
List<Order> findByItemsQuantity(int quantity);
@Query("{ "items.quantity": ?0 }")
List<Order> findWithQuery(int quantity);
}
codecentric AG 28
Spring Data MongoDB: Additional Goodies
 Map/Reduce / Aggregation framework
 Index Management
 Support for GridFS
 Geopspatial indexes / queries
 Optimistic Locking
codecentric AG 29
Hibernate OGM
codecentric AG 30
Hibernate OGM MongoDB – Fact Sheet
Vendor JBoss / Redhat
License GNU LGPL, Version 2.1
Documentation http://www.hibernate.org/subprojects/ogm.html
Main Features • JPA API (Subset)
• JPQL Query Language
codecentric AG 31
Hibernate OGM
 Implements JPA API (subset)
 JP-QL query are translated to native
datastore queries
 Supports Infinispan, EhCache, MongoDB
codecentric AG 32
Hibernate OGM
Architecture
Source:
http://docs.jboss.org/hibernate/ogm/4.0/reference/en-
US/html/ogm-architecture.html#d0e409
codecentric AG 33
Hibernate OGM MongoDB: Configuration
<persistence version="2.0" …>
<persistence-unit name="primary">
<provider>org.hibernate.ogm.jpa.HibernateOgmPersistence</provider>
<class>hibernate.Order</class>
<class>hibernate.Item</class>
<properties>
<property name="hibernate.ogm.datastore.provider"
value="org.hibernate.ogm.datastore.mongodb.impl.MongoDBDatastoreProvider"/>
<property name="hibernate.ogm.mongodb.database" value=„odm"/>
<property name="hibernate.ogm.mongodb.host" value=„localhost"/>
<property name="hibernate.ogm.mongodb.port" value=„27017"/>
</properties>
</persistence-unit>
</persistence>
codecentric AG 34
Hibernate OGM MongoDB: Object Mapping
@Entity
@NamedQuery(
name="byItemsQuantity",
query = "SELECT o FROM Order o JOIN o.items i WHERE i.quantity = :quantity"
)
public class Order {
@GeneratedValue(generator = "uuid")
@GenericGenerator(name = "uuid", strategy = "uuid2")
@Id private String id;
private Date date;
@Column(name = "custInfo") private String customerInfo;
@ElementCollection
private List<Item> items;
codecentric AG 35
Hibernate OGM MongoDB: Object Mapping
@Embeddable
public class Item {
private int quantity;
private double price;
@Column(name="desc") private String description;
...
codecentric AG 36
Hibernate OGM: Summary
 Very early beta
 Only persist / merge / remove
 No query support (yet)
 Uses relational API
codecentric AG 37
Hibernate OGM: OgmEntityManager
codecentric AG 38
Morphia
codecentric AG 39
Morphia – Fact Sheet
Developer Scott Hernandez, James Green
License Apache License, Version 2.0
Documentation https://github.com/jmkgreen/morphia/wiki/Overview
Main Features • Object/Document Mapping
• Custom Query API
• DAO support
codecentric AG 40
Morphia: Object Mapping
public class Order {
@Id private ObjectId id;
private Date date;
@Property("custInfo") private String customerInfo;
@Embedded List<Item> items;
...
}
public class Item {
private int quantity;
private double price;
@Property("desc") private String description;
...
}
codecentric AG 41
Morphia: Queries
public class OrderDao extends BasicDAO<Order, ObjectId> {
List<Order> findByItemsQuantity(int quantity) {
return
find( createQuery().filter("items.quantity", quantity))
.asList();
}
List<Order> findByItemsPriceGreaterThan(double price) {
return
find( createQuery().field("items.price").greaterThan(price) )
.asList();
}
…
}
codecentric AG 42
Morphia: Custom query syntax – why?
Morphia Mongo Query
= $eq
!=, <> $neq
>, <, >=,<= $gt, $lt, $gte, $lte
in, nin $in, $nin
elem $elemMatch
… ….
codecentric AG 43
Jongo
codecentric AG 44
Jongo – Fact Sheet
Developer Benoît Guérout, Yves Amsellem
License Apache License, Version 2.0
Documentation http://jongo.org/
Main Features • Object/Document Mapping
• Custom Query API
codecentric AG 45
Jongo: Object Mapping
public class Order {
private ObjectId id;
private Date date;
@JsonProperty("custInfo") private String customerInfo;
List<Item> items;
… }
public class Item {
private int quantity;
private double price;
@JsonProperty("desc") private String description;
…
}
codecentric AG 46
Jongo: Queries
// Java driver API
MongoClient mc = new MongoClient();
DB db = mc.getDB("odm_jongo");
// Jongo API entry point
Jongo jongo = new Jongo(db);
MongoCollection orders = jongo.getCollection("order");
// no DAO needed
Iterable<Order> result =
orders.find("{"items.quantity": #}", 2).as(Order.class);
// supports projection
Iterable<X> result =
orders.find().fields("{_id:0, date:1, custInfo:1}").as(X.class);
codecentric AG 47
Judge yourself …
Spring Data MongoDB
https://github.com/ttrelle/spring-data-examples
Hibernate OGM MongoDB
https://github.com/ttrelle/hibernate-ogm-examples
Jongo
https://github.com/ttrelle/jongo-examples
Morphia
https://github.com/ttrelle/morphia-mongodb-examples
codecentric AG 48
Summary
ODM
Annotations
Queries
Java Driver -- Nested BasicDBObject‘s
Spring Data MongoDB Custom Interface w/
- derived queries
- JSON queries
Hibernate OGM JPA JPQL: @Named(Native)Query +
EntityManager
Jongo Jackson JSON queries via collection
wrapper
Morphia Custom BasicDAO super class w/ 2
flavours of fluent API
codecentric AG 49
Which one should I use?
Hibernate OGM
Spring Data
MongoDB
MongoDB Java Driver
Morphia
JPA
JDBC
MongoDB
Jongo
- Ready for production
- Supported by 10gen
Mature
- Ready for production
- Active community
-Too early to judge
- API mismatch
The „better“ driver
codecentric AG 50
MongoDB User Group Düsseldorf
https://www.xing.com/net/mongodb-dus
@MongoDUS
MUG Düsseldorf
codecentric AG 51
QUESTIONS?
Tobias Trelle
codecentric AG
Merscheider Str. 1
42699 Solingen
tel +49 (0) 212.233628.47
fax +49 (0) 212.233628.79
mail Tobias.Trelle@codecentric.de
twitter @tobiastrelle
www.codecentric.de
blog.codecentric.de/en/author/tobias-trelle
www.xing.com/net/mongodb-dus

Contenu connexe

Tendances

MongoDB: Easy Java Persistence with Morphia
MongoDB: Easy Java Persistence with MorphiaMongoDB: Easy Java Persistence with Morphia
MongoDB: Easy Java Persistence with MorphiaScott Hernandez
 
Java Development with MongoDB
Java Development with MongoDBJava Development with MongoDB
Java Development with MongoDBScott Hernandez
 
BedCon 2013 - Java Persistenz-Frameworks für MongoDB
BedCon 2013 - Java Persistenz-Frameworks für MongoDBBedCon 2013 - Java Persistenz-Frameworks für MongoDB
BedCon 2013 - Java Persistenz-Frameworks für MongoDBTobias Trelle
 
MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know Norberto Leite
 
Building Spring Data with MongoDB
Building Spring Data with MongoDBBuilding Spring Data with MongoDB
Building Spring Data with MongoDBMongoDB
 
Map/Confused? A practical approach to Map/Reduce with MongoDB
Map/Confused? A practical approach to Map/Reduce with MongoDBMap/Confused? A practical approach to Map/Reduce with MongoDB
Map/Confused? A practical approach to Map/Reduce with MongoDBUwe Printz
 
Webinar: Building Your First App with MongoDB and Java
Webinar: Building Your First App with MongoDB and JavaWebinar: Building Your First App with MongoDB and Java
Webinar: Building Your First App with MongoDB and JavaMongoDB
 
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...MongoDB
 
Getting Started with MongoDB and NodeJS
Getting Started with MongoDB and NodeJSGetting Started with MongoDB and NodeJS
Getting Started with MongoDB and NodeJSMongoDB
 
MongoDB Performance Tuning
MongoDB Performance TuningMongoDB Performance Tuning
MongoDB Performance TuningPuneet Behl
 
Indexing Strategies to Help You Scale
Indexing Strategies to Help You ScaleIndexing Strategies to Help You Scale
Indexing Strategies to Help You ScaleMongoDB
 
Data access 2.0? Please welcome: Spring Data!
Data access 2.0? Please welcome: Spring Data!Data access 2.0? Please welcome: Spring Data!
Data access 2.0? Please welcome: Spring Data!Oliver Gierke
 
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
 
Introduction to Restkit
Introduction to RestkitIntroduction to Restkit
Introduction to Restkitpetertmarks
 
NoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love StoryNoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love StoryAlexandre Morgaut
 
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
 
Fast querying indexing for performance (4)
Fast querying   indexing for performance (4)Fast querying   indexing for performance (4)
Fast querying indexing for performance (4)MongoDB
 
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
 

Tendances (19)

MongoDB: Easy Java Persistence with Morphia
MongoDB: Easy Java Persistence with MorphiaMongoDB: Easy Java Persistence with Morphia
MongoDB: Easy Java Persistence with Morphia
 
Java Development with MongoDB
Java Development with MongoDBJava Development with MongoDB
Java Development with MongoDB
 
BedCon 2013 - Java Persistenz-Frameworks für MongoDB
BedCon 2013 - Java Persistenz-Frameworks für MongoDBBedCon 2013 - Java Persistenz-Frameworks für MongoDB
BedCon 2013 - Java Persistenz-Frameworks für MongoDB
 
MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know
 
Building Spring Data with MongoDB
Building Spring Data with MongoDBBuilding Spring Data with MongoDB
Building Spring Data with MongoDB
 
Map/Confused? A practical approach to Map/Reduce with MongoDB
Map/Confused? A practical approach to Map/Reduce with MongoDBMap/Confused? A practical approach to Map/Reduce with MongoDB
Map/Confused? A practical approach to Map/Reduce with MongoDB
 
Webinar: Building Your First App with MongoDB and Java
Webinar: Building Your First App with MongoDB and JavaWebinar: Building Your First App with MongoDB and Java
Webinar: Building Your First App with MongoDB and Java
 
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...
 
Getting Started with MongoDB and NodeJS
Getting Started with MongoDB and NodeJSGetting Started with MongoDB and NodeJS
Getting Started with MongoDB and NodeJS
 
MongoDB Performance Tuning
MongoDB Performance TuningMongoDB Performance Tuning
MongoDB Performance Tuning
 
Indexing Strategies to Help You Scale
Indexing Strategies to Help You ScaleIndexing Strategies to Help You Scale
Indexing Strategies to Help You Scale
 
Data access 2.0? Please welcome: Spring Data!
Data access 2.0? Please welcome: Spring Data!Data access 2.0? Please welcome: Spring Data!
Data access 2.0? Please welcome: Spring Data!
 
An introduction to MongoDB
An introduction to MongoDBAn introduction to MongoDB
An introduction to MongoDB
 
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
 
Introduction to Restkit
Introduction to RestkitIntroduction to Restkit
Introduction to Restkit
 
NoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love StoryNoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love Story
 
What do you mean, Backwards Compatibility?
What do you mean, Backwards Compatibility?What do you mean, Backwards Compatibility?
What do you mean, Backwards Compatibility?
 
Fast querying indexing for performance (4)
Fast querying   indexing for performance (4)Fast querying   indexing for performance (4)
Fast querying indexing for performance (4)
 
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
 

En vedette

The Spring Data MongoDB Project
The Spring Data MongoDB ProjectThe Spring Data MongoDB Project
The Spring Data MongoDB ProjectMongoDB
 
Hadoop, the Apple of Our Eyes (這些年,我們一起追的 Hadoop)
Hadoop, the Apple of Our Eyes (這些年,我們一起追的 Hadoop)Hadoop, the Apple of Our Eyes (這些年,我們一起追的 Hadoop)
Hadoop, the Apple of Our Eyes (這些年,我們一起追的 Hadoop)Kuo-Chun Su
 
The Aggregation Framework
The Aggregation FrameworkThe Aggregation Framework
The Aggregation FrameworkMongoDB
 
MongoDB for Time Series Data Part 2: Analyzing Time Series Data Using the Agg...
MongoDB for Time Series Data Part 2: Analyzing Time Series Data Using the Agg...MongoDB for Time Series Data Part 2: Analyzing Time Series Data Using the Agg...
MongoDB for Time Series Data Part 2: Analyzing Time Series Data Using the Agg...MongoDB
 
MongoDB Analytics: Learn Aggregation by Example - Exploratory Analytics and V...
MongoDB Analytics: Learn Aggregation by Example - Exploratory Analytics and V...MongoDB Analytics: Learn Aggregation by Example - Exploratory Analytics and V...
MongoDB Analytics: Learn Aggregation by Example - Exploratory Analytics and V...MongoDB
 
Are You Ready to Cut The Cable?
Are You Ready to Cut The Cable?Are You Ready to Cut The Cable?
Are You Ready to Cut The Cable?Mkv Xstream
 
Port folio 20121005
Port folio 20121005Port folio 20121005
Port folio 20121005Thành Mắm
 
Introducing Eaton Square
Introducing Eaton SquareIntroducing Eaton Square
Introducing Eaton SquareNick Kelly
 
Сомниум Нетворк-Новая презентация!
Сомниум Нетворк-Новая презентация!Сомниум Нетворк-Новая презентация!
Сомниум Нетворк-Новая презентация!onlinesarabotok
 
The Social Challenge of 1.5°C Webinar: Ilan Chabay
The Social Challenge of 1.5°C Webinar: Ilan ChabayThe Social Challenge of 1.5°C Webinar: Ilan Chabay
The Social Challenge of 1.5°C Webinar: Ilan Chabaytewksjj
 
Scaling wordpress for high traffic
Scaling wordpress for high trafficScaling wordpress for high traffic
Scaling wordpress for high trafficRoshan Bhattarai
 
2 power and hydrogen generation figures
2 power and hydrogen generation figures2 power and hydrogen generation figures
2 power and hydrogen generation figuresnovi5036
 

En vedette (15)

The Spring Data MongoDB Project
The Spring Data MongoDB ProjectThe Spring Data MongoDB Project
The Spring Data MongoDB Project
 
Hadoop, the Apple of Our Eyes (這些年,我們一起追的 Hadoop)
Hadoop, the Apple of Our Eyes (這些年,我們一起追的 Hadoop)Hadoop, the Apple of Our Eyes (這些年,我們一起追的 Hadoop)
Hadoop, the Apple of Our Eyes (這些年,我們一起追的 Hadoop)
 
The Aggregation Framework
The Aggregation FrameworkThe Aggregation Framework
The Aggregation Framework
 
MongoDB for Time Series Data Part 2: Analyzing Time Series Data Using the Agg...
MongoDB for Time Series Data Part 2: Analyzing Time Series Data Using the Agg...MongoDB for Time Series Data Part 2: Analyzing Time Series Data Using the Agg...
MongoDB for Time Series Data Part 2: Analyzing Time Series Data Using the Agg...
 
MongoDB Analytics: Learn Aggregation by Example - Exploratory Analytics and V...
MongoDB Analytics: Learn Aggregation by Example - Exploratory Analytics and V...MongoDB Analytics: Learn Aggregation by Example - Exploratory Analytics and V...
MongoDB Analytics: Learn Aggregation by Example - Exploratory Analytics and V...
 
Are You Ready to Cut The Cable?
Are You Ready to Cut The Cable?Are You Ready to Cut The Cable?
Are You Ready to Cut The Cable?
 
Port folio 20121005
Port folio 20121005Port folio 20121005
Port folio 20121005
 
Happy-bday-reechal
Happy-bday-reechalHappy-bday-reechal
Happy-bday-reechal
 
Pautas
PautasPautas
Pautas
 
Copy of shortckt
Copy of shortcktCopy of shortckt
Copy of shortckt
 
Introducing Eaton Square
Introducing Eaton SquareIntroducing Eaton Square
Introducing Eaton Square
 
Сомниум Нетворк-Новая презентация!
Сомниум Нетворк-Новая презентация!Сомниум Нетворк-Новая презентация!
Сомниум Нетворк-Новая презентация!
 
The Social Challenge of 1.5°C Webinar: Ilan Chabay
The Social Challenge of 1.5°C Webinar: Ilan ChabayThe Social Challenge of 1.5°C Webinar: Ilan Chabay
The Social Challenge of 1.5°C Webinar: Ilan Chabay
 
Scaling wordpress for high traffic
Scaling wordpress for high trafficScaling wordpress for high traffic
Scaling wordpress for high traffic
 
2 power and hydrogen generation figures
2 power and hydrogen generation figures2 power and hydrogen generation figures
2 power and hydrogen generation figures
 

Similaire à Morphia, Spring Data & Co.

Building your first app with MongoDB
Building your first app with MongoDBBuilding your first app with MongoDB
Building your first app with MongoDBNorberto Leite
 
Webinar: Building Your First App
Webinar: Building Your First AppWebinar: Building Your First App
Webinar: Building Your First AppMongoDB
 
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
 
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
 
Getting started with MongoDB and Scala - Open Source Bridge 2012
Getting started with MongoDB and Scala - Open Source Bridge 2012Getting started with MongoDB and Scala - Open Source Bridge 2012
Getting started with MongoDB and Scala - Open Source Bridge 2012sullis
 
Java Development with MongoDB (James Williams)
Java Development with MongoDB (James Williams)Java Development with MongoDB (James Williams)
Java Development with MongoDB (James Williams)MongoSF
 
Spring Data MongoDB 介紹
Spring Data MongoDB 介紹Spring Data MongoDB 介紹
Spring Data MongoDB 介紹Kuo-Chun Su
 
Mongodb ExpressJS HandlebarsJS NodeJS FullStack
Mongodb ExpressJS HandlebarsJS NodeJS FullStackMongodb ExpressJS HandlebarsJS NodeJS FullStack
Mongodb ExpressJS HandlebarsJS NodeJS FullStackNarendranath Reddy
 
How to use MongoDB with CakePHP
How to use MongoDB with CakePHPHow to use MongoDB with CakePHP
How to use MongoDB with CakePHPichikaway
 
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
 
Dev Jumpstart: Building Your First App
Dev Jumpstart: Building Your First AppDev Jumpstart: Building Your First App
Dev Jumpstart: Building Your First AppMongoDB
 
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
 
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
 
Mongo db eveningschemadesign
Mongo db eveningschemadesignMongo db eveningschemadesign
Mongo db eveningschemadesignMongoDB APAC
 
Webinar: Building Your First MongoDB App
Webinar: Building Your First MongoDB AppWebinar: Building Your First MongoDB App
Webinar: Building Your First MongoDB AppMongoDB
 
Back to Basics 2017: Mí primera aplicación MongoDB
Back to Basics 2017: Mí primera aplicación MongoDBBack to Basics 2017: Mí primera aplicación MongoDB
Back to Basics 2017: Mí primera aplicación MongoDBMongoDB
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBChun-Kai Wang
 
Test Automation for NoSQL Databases
Test Automation for NoSQL DatabasesTest Automation for NoSQL Databases
Test Automation for NoSQL DatabasesTobias Trelle
 
Building Your First Application with MongoDB
Building Your First Application with MongoDBBuilding Your First Application with MongoDB
Building Your First Application with MongoDBMongoDB
 

Similaire à Morphia, Spring Data & Co. (20)

Building your first app with MongoDB
Building your first app with MongoDBBuilding your first app with MongoDB
Building your first app with MongoDB
 
Webinar: Building Your First App
Webinar: Building Your First AppWebinar: Building Your First App
Webinar: Building Your First App
 
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
 
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
 
Getting started with MongoDB and Scala - Open Source Bridge 2012
Getting started with MongoDB and Scala - Open Source Bridge 2012Getting started with MongoDB and Scala - Open Source Bridge 2012
Getting started with MongoDB and Scala - Open Source Bridge 2012
 
Java Development with MongoDB (James Williams)
Java Development with MongoDB (James Williams)Java Development with MongoDB (James Williams)
Java Development with MongoDB (James Williams)
 
Spring Data MongoDB 介紹
Spring Data MongoDB 介紹Spring Data MongoDB 介紹
Spring Data MongoDB 介紹
 
Mongodb ExpressJS HandlebarsJS NodeJS FullStack
Mongodb ExpressJS HandlebarsJS NodeJS FullStackMongodb ExpressJS HandlebarsJS NodeJS FullStack
Mongodb ExpressJS HandlebarsJS NodeJS FullStack
 
How to use MongoDB with CakePHP
How to use MongoDB with CakePHPHow to use MongoDB with CakePHP
How to use MongoDB with CakePHP
 
Green dao
Green daoGreen dao
Green dao
 
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
 
Dev Jumpstart: Building Your First App
Dev Jumpstart: Building Your First AppDev Jumpstart: Building Your First App
Dev Jumpstart: Building Your First App
 
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)
 
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
 
Mongo db eveningschemadesign
Mongo db eveningschemadesignMongo db eveningschemadesign
Mongo db eveningschemadesign
 
Webinar: Building Your First MongoDB App
Webinar: Building Your First MongoDB AppWebinar: Building Your First MongoDB App
Webinar: Building Your First MongoDB App
 
Back to Basics 2017: Mí primera aplicación MongoDB
Back to Basics 2017: Mí primera aplicación MongoDBBack to Basics 2017: Mí primera aplicación MongoDB
Back to Basics 2017: Mí primera aplicación MongoDB
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Test Automation for NoSQL Databases
Test Automation for NoSQL DatabasesTest Automation for NoSQL Databases
Test Automation for NoSQL Databases
 
Building Your First Application with MongoDB
Building Your First Application with MongoDBBuilding Your First Application with MongoDB
Building Your First Application with MongoDB
 

Plus de Tobias Trelle

TDD mit JUnit und Mockito
TDD mit JUnit und MockitoTDD mit JUnit und Mockito
TDD mit JUnit und MockitoTobias Trelle
 
NoSQL - Einführung in Graphen-Datenbanken mit Neo4j
NoSQL - Einführung in Graphen-Datenbanken mit Neo4jNoSQL - Einführung in Graphen-Datenbanken mit Neo4j
NoSQL - Einführung in Graphen-Datenbanken mit Neo4jTobias Trelle
 
Einführung in NoSQL-Datenbanken
Einführung in NoSQL-DatenbankenEinführung in NoSQL-Datenbanken
Einführung in NoSQL-DatenbankenTobias Trelle
 
MongoDB - Riesige Datenmengen schemafrei verwalten
MongoDB - Riesige Datenmengen schemafrei verwaltenMongoDB - Riesige Datenmengen schemafrei verwalten
MongoDB - Riesige Datenmengen schemafrei verwaltenTobias Trelle
 
Morphia, Spring Data & Co
Morphia, Spring Data & CoMorphia, Spring Data & Co
Morphia, Spring Data & CoTobias Trelle
 
An introduction to MongoDB and Ruby
An introduction to MongoDB and RubyAn introduction to MongoDB and Ruby
An introduction to MongoDB and RubyTobias Trelle
 
OOP 2013: Praktische Einführung in MongoDB
OOP 2013: Praktische Einführung in MongoDBOOP 2013: Praktische Einführung in MongoDB
OOP 2013: Praktische Einführung in MongoDBTobias Trelle
 
MongoDB Munich 2012: Spring Data MongoDB
MongoDB Munich 2012: Spring Data MongoDBMongoDB Munich 2012: Spring Data MongoDB
MongoDB Munich 2012: Spring Data MongoDBTobias Trelle
 
MongoDB Live Hacking
MongoDB Live HackingMongoDB Live Hacking
MongoDB Live HackingTobias Trelle
 

Plus de Tobias Trelle (10)

TDD mit JUnit und Mockito
TDD mit JUnit und MockitoTDD mit JUnit und Mockito
TDD mit JUnit und Mockito
 
NoSQL - Einführung in Graphen-Datenbanken mit Neo4j
NoSQL - Einführung in Graphen-Datenbanken mit Neo4jNoSQL - Einführung in Graphen-Datenbanken mit Neo4j
NoSQL - Einführung in Graphen-Datenbanken mit Neo4j
 
Einführung in NoSQL-Datenbanken
Einführung in NoSQL-DatenbankenEinführung in NoSQL-Datenbanken
Einführung in NoSQL-Datenbanken
 
MongoDB Einführung
MongoDB EinführungMongoDB Einführung
MongoDB Einführung
 
MongoDB - Riesige Datenmengen schemafrei verwalten
MongoDB - Riesige Datenmengen schemafrei verwaltenMongoDB - Riesige Datenmengen schemafrei verwalten
MongoDB - Riesige Datenmengen schemafrei verwalten
 
Morphia, Spring Data & Co
Morphia, Spring Data & CoMorphia, Spring Data & Co
Morphia, Spring Data & Co
 
An introduction to MongoDB and Ruby
An introduction to MongoDB and RubyAn introduction to MongoDB and Ruby
An introduction to MongoDB and Ruby
 
OOP 2013: Praktische Einführung in MongoDB
OOP 2013: Praktische Einführung in MongoDBOOP 2013: Praktische Einführung in MongoDB
OOP 2013: Praktische Einführung in MongoDB
 
MongoDB Munich 2012: Spring Data MongoDB
MongoDB Munich 2012: Spring Data MongoDBMongoDB Munich 2012: Spring Data MongoDB
MongoDB Munich 2012: Spring Data MongoDB
 
MongoDB Live Hacking
MongoDB Live HackingMongoDB Live Hacking
MongoDB Live Hacking
 

Dernier

unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
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
 
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
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
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
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
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
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 

Dernier (20)

unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
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
 
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
 
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
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
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
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
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
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 

Morphia, Spring Data & Co.

  • 1. codecentric AG 1 Morphia, Spring Data & Co. - Java Persistenz-Frameworks für MongoDB Tobias.Trelle@codecentric.de @tobiastrelle
  • 2. codecentric AG 2 Tobias Trelle - Senior IT Consultant @ codecentric AG (Düsseldorf) - Organisator MongoDB Usergruppe Düsseldorf - Autor MongoDB-Buch (dpunkt-Verlag)
  • 3. codecentric AG 3 Where have all my tables gone … ORM is dead long live ODM
  • 4. codecentric AG 4 MongoDB?  NoSQL-Datenbank / Open Source  Dokumentenorientiert  Hochperformant, horizontal skalierbar (scale-out)  Replication & Sharding out-of-the-box  Map/Reduce  Geospatial Indexes / Queries
  • 5. codecentric AG 5 Grundkonzept MongoDB-Server Server Database Collection Document Field Tabelle Zeile Spalte Relationales Pendant Aber … Flexibles Schema - Arrays - Rekursiv
  • 6. codecentric AG 6 Document { title: „Praxisbuch Mongo“, version: 0.1, copies_sold: 0, authors: [ { name: „Uwe Seiler“, email: „uwe.seiler@codecentric.de“ }, { name: „Tobias Trelle“, email: „tobias.trelle@codecentric.de“} ] }
  • 7. codecentric AG 7 JSON vs. BSON { hello: "MongoDB" } x18x00x00x00 x02 hellox00 x08x00x00x00MongoDBx00 x00
  • 8. codecentric AG 8 CRUD = IFUR insert(…) find(…), findOne(…) update(…) remove()
  • 9. codecentric AG 9 Java Persistenz mit MongoDB MongoDB Java Driver Spring Data MongoDB Morphia Hibernate OGM Jongo
  • 10. codecentric AG 10 Use Case db.order.find( {"items.quantity": ? } )
  • 11. codecentric AG 11 Mongo Java Driver
  • 12. codecentric AG 12 MongoDB Drivers  One wire protocol for all client languages  A driver implementation per language  Responsibilities:  Converting language dependent data structures   BSON  Generating ObjectId for _id field  Overview: http://www.mongodb.org/display/DOCS/Drivers
  • 13. codecentric AG 13 MongoDB Java Driver One JAR w/o further dependencies: <dependency> <groupId>org.mongodb</groupId> <artifactId>mongo-java-driver</artifactId> <version>2.11.3</version> </dependency> github: https://github.com/mongodb/mongo-java-driver
  • 14. codecentric AG 14 Java Driver: Connect to MongoDB import com.mongodb.MongoClient; // Default: localhost:27017 mongo = new MongoClient(); // Sharding: mongos server mongo = new MongoClient("mongos01", 4711); // Replica set mongo = new MongoClient(Arrays.asList( new ServerAddress("replicant01", 10001), new ServerAddress("replicant02", 10002), new ServerAddress("replicant03", 10003) ));
  • 15. codecentric AG 15 Java Driver: Database / Collection import com.mongodb.DB; import com.mongodb.DBCollection; DB db = mongo.getDB("test"); DBCollection collection = db.getCollection("foo");
  • 16. codecentric AG 16 Java Driver: Documents import com.mongodb.BasicDBObject; import com.mongodb.DBObject; // insert document DBObject doc = new BasicDBObject(); doc.put("date", new Date()); doc.put("i", 42); collection.insert(doc);
  • 17. codecentric AG 17 Java Driver: Queries import com.mongodb.DBCursor; DBCursor cursor; cursor = collection.find(); // all documents // documents w/ {i: 42} cursor = collection.find( new BasicDBObject("i", 42) ); document = cursor.next(); ...
  • 18. codecentric AG 18 Java Driver: Order Use Case DB db = mongo.getDB("test"); DBCollection collection = db.getCollection("order"); DBObject order; List<DBObject> items = new ArrayList<DBObject>(); DBObject item; // order order = new BasicDBObject(); order.put("date", new Date()); order.put("custInfo" , "Tobias Trelle"); order.put("items", items); // items item = new BasicDBObject(); item.put("quantity", 1); item.put("price", 47.11); item.put("desc", "Item #1"); items.add(item); item = new BasicDBObject(); item.put("quantity", 2); item.put("price", 42.0); item.put("desc", "Item #2"); items.add(item); collection.insert(order);
  • 19. codecentric AG 19 Java Driver: Order Use Case DB db = mongo.getDB("test"); DBCollection collection = db.getCollection("order"); DBObject query; DBObject document; DBCursor cursor; query = new BasicDBObject("items.quantity", 2); cursor = collection.find(query); while ( cursor.hasNext() ) { document = cursor.next(); println(document); }
  • 20. codecentric AG 20 Spring Data MongoDB
  • 21. codecentric AG 21 Spring Data MongoDB – Fact Sheet Vendor VMware / SpringSource License Apache License, Version 2.0 Documentation http://www.springsource.org/spring-data/mongodb Main Features • Repository Support • Object/Document Mapping • Templating
  • 22. codecentric AG 22 Spring Data Common patterns for RDBMS and NoSQL data stores Spring Data RDBMS MongoDB Neo4j … Spring Data JPA CrudRepository PagingAndSortingRepository JpaRepository JPA JDBC Spring Data MongoDB MongoRepository MongoTemplate Spring Data Neo4j Spring Data … GraphRepository Neo4jTemplate Mongo Java Driver Embedded REST Quelle: http://www.infoq.com/articles/spring-data-intro
  • 23. codecentric AG 23 Spring Data MongoDB Templating  Resource abstraction  Configure connections to mongod / mongos node(s)  Collection lifecycle ( create, drop)  Map/Reduce / Aggregation Object Mapping  Annotation based: @Document, @Field, @Index etc.  Classes are mapped to collections, Java Objects to documents Repository Support  Queries are derived from methods signatures  Annotated Queries
  • 24. codecentric AG 24 Spring Data MongoDB: Configuration <!-- Connection to MongoDB server --> <mongo:db-factory host="localhost" port="27017" dbname="test" /> <!-- MongoDB Template --> <bean id="mongoTemplate„ class="org.springframework.data.mongodb.core.MongoTemplate"> <constructor-arg name="mongoDbFactory" ref="mongoDbFactory"/> </bean> <!-- Package w/ automagic repositories --> <mongo:repositories base-package="mongodb" />
  • 25. codecentric AG 26 Spring Data MongoDB: Object Mapping public class Order { @Id private String id; private Date date; @Field("custInfo") private String customerInfo; List<Item> items; ... } public class Item { private int quantity; private double price; @Field("desc") private String description; ... }
  • 26. codecentric AG 27 Spring Data MongoDB: Repository Support public interface OrderRepository extends MongoRepository<Order, String> { List<Order> findByItemsQuantity(int quantity); @Query("{ "items.quantity": ?0 }") List<Order> findWithQuery(int quantity); }
  • 27. codecentric AG 28 Spring Data MongoDB: Additional Goodies  Map/Reduce / Aggregation framework  Index Management  Support for GridFS  Geopspatial indexes / queries  Optimistic Locking
  • 29. codecentric AG 30 Hibernate OGM MongoDB – Fact Sheet Vendor JBoss / Redhat License GNU LGPL, Version 2.1 Documentation http://www.hibernate.org/subprojects/ogm.html Main Features • JPA API (Subset) • JPQL Query Language
  • 30. codecentric AG 31 Hibernate OGM  Implements JPA API (subset)  JP-QL query are translated to native datastore queries  Supports Infinispan, EhCache, MongoDB
  • 31. codecentric AG 32 Hibernate OGM Architecture Source: http://docs.jboss.org/hibernate/ogm/4.0/reference/en- US/html/ogm-architecture.html#d0e409
  • 32. codecentric AG 33 Hibernate OGM MongoDB: Configuration <persistence version="2.0" …> <persistence-unit name="primary"> <provider>org.hibernate.ogm.jpa.HibernateOgmPersistence</provider> <class>hibernate.Order</class> <class>hibernate.Item</class> <properties> <property name="hibernate.ogm.datastore.provider" value="org.hibernate.ogm.datastore.mongodb.impl.MongoDBDatastoreProvider"/> <property name="hibernate.ogm.mongodb.database" value=„odm"/> <property name="hibernate.ogm.mongodb.host" value=„localhost"/> <property name="hibernate.ogm.mongodb.port" value=„27017"/> </properties> </persistence-unit> </persistence>
  • 33. codecentric AG 34 Hibernate OGM MongoDB: Object Mapping @Entity @NamedQuery( name="byItemsQuantity", query = "SELECT o FROM Order o JOIN o.items i WHERE i.quantity = :quantity" ) public class Order { @GeneratedValue(generator = "uuid") @GenericGenerator(name = "uuid", strategy = "uuid2") @Id private String id; private Date date; @Column(name = "custInfo") private String customerInfo; @ElementCollection private List<Item> items;
  • 34. codecentric AG 35 Hibernate OGM MongoDB: Object Mapping @Embeddable public class Item { private int quantity; private double price; @Column(name="desc") private String description; ...
  • 35. codecentric AG 36 Hibernate OGM: Summary  Very early beta  Only persist / merge / remove  No query support (yet)  Uses relational API
  • 36. codecentric AG 37 Hibernate OGM: OgmEntityManager
  • 38. codecentric AG 39 Morphia – Fact Sheet Developer Scott Hernandez, James Green License Apache License, Version 2.0 Documentation https://github.com/jmkgreen/morphia/wiki/Overview Main Features • Object/Document Mapping • Custom Query API • DAO support
  • 39. codecentric AG 40 Morphia: Object Mapping public class Order { @Id private ObjectId id; private Date date; @Property("custInfo") private String customerInfo; @Embedded List<Item> items; ... } public class Item { private int quantity; private double price; @Property("desc") private String description; ... }
  • 40. codecentric AG 41 Morphia: Queries public class OrderDao extends BasicDAO<Order, ObjectId> { List<Order> findByItemsQuantity(int quantity) { return find( createQuery().filter("items.quantity", quantity)) .asList(); } List<Order> findByItemsPriceGreaterThan(double price) { return find( createQuery().field("items.price").greaterThan(price) ) .asList(); } … }
  • 41. codecentric AG 42 Morphia: Custom query syntax – why? Morphia Mongo Query = $eq !=, <> $neq >, <, >=,<= $gt, $lt, $gte, $lte in, nin $in, $nin elem $elemMatch … ….
  • 43. codecentric AG 44 Jongo – Fact Sheet Developer Benoît Guérout, Yves Amsellem License Apache License, Version 2.0 Documentation http://jongo.org/ Main Features • Object/Document Mapping • Custom Query API
  • 44. codecentric AG 45 Jongo: Object Mapping public class Order { private ObjectId id; private Date date; @JsonProperty("custInfo") private String customerInfo; List<Item> items; … } public class Item { private int quantity; private double price; @JsonProperty("desc") private String description; … }
  • 45. codecentric AG 46 Jongo: Queries // Java driver API MongoClient mc = new MongoClient(); DB db = mc.getDB("odm_jongo"); // Jongo API entry point Jongo jongo = new Jongo(db); MongoCollection orders = jongo.getCollection("order"); // no DAO needed Iterable<Order> result = orders.find("{"items.quantity": #}", 2).as(Order.class); // supports projection Iterable<X> result = orders.find().fields("{_id:0, date:1, custInfo:1}").as(X.class);
  • 46. codecentric AG 47 Judge yourself … Spring Data MongoDB https://github.com/ttrelle/spring-data-examples Hibernate OGM MongoDB https://github.com/ttrelle/hibernate-ogm-examples Jongo https://github.com/ttrelle/jongo-examples Morphia https://github.com/ttrelle/morphia-mongodb-examples
  • 47. codecentric AG 48 Summary ODM Annotations Queries Java Driver -- Nested BasicDBObject‘s Spring Data MongoDB Custom Interface w/ - derived queries - JSON queries Hibernate OGM JPA JPQL: @Named(Native)Query + EntityManager Jongo Jackson JSON queries via collection wrapper Morphia Custom BasicDAO super class w/ 2 flavours of fluent API
  • 48. codecentric AG 49 Which one should I use? Hibernate OGM Spring Data MongoDB MongoDB Java Driver Morphia JPA JDBC MongoDB Jongo - Ready for production - Supported by 10gen Mature - Ready for production - Active community -Too early to judge - API mismatch The „better“ driver
  • 49. codecentric AG 50 MongoDB User Group Düsseldorf https://www.xing.com/net/mongodb-dus @MongoDUS MUG Düsseldorf
  • 50. codecentric AG 51 QUESTIONS? Tobias Trelle codecentric AG Merscheider Str. 1 42699 Solingen tel +49 (0) 212.233628.47 fax +49 (0) 212.233628.79 mail Tobias.Trelle@codecentric.de twitter @tobiastrelle www.codecentric.de blog.codecentric.de/en/author/tobias-trelle www.xing.com/net/mongodb-dus