MongoDB and Spring - Two leaves of a same tree
-
Upload
mongodb -
Category
Technology
-
view
987 -
download
2
Transcript of MongoDB and Spring - Two leaves of a same tree
![Page 1: MongoDB and Spring - Two leaves of a same tree](https://reader030.fdocuments.us/reader030/viewer/2022032421/55a67ca01a28ab4f568b46ae/html5/thumbnails/1.jpg)
![Page 2: MongoDB and Spring - Two leaves of a same tree](https://reader030.fdocuments.us/reader030/viewer/2022032421/55a67ca01a28ab4f568b46ae/html5/thumbnails/2.jpg)
MongoDB + Spring
Norberto Leite
@nleite
http://www.mongodb.com/norberto
Two leafs of the same tree
![Page 3: MongoDB and Spring - Two leaves of a same tree](https://reader030.fdocuments.us/reader030/viewer/2022032421/55a67ca01a28ab4f568b46ae/html5/thumbnails/3.jpg)
3
Agenda
• MongoDB Introduction
– Just in case you've been distracted
• Spring Framework Overview
• Spring + MongoDB
– Spring Data
– Spring Boot
– Spring Batch
![Page 4: MongoDB and Spring - Two leaves of a same tree](https://reader030.fdocuments.us/reader030/viewer/2022032421/55a67ca01a28ab4f568b46ae/html5/thumbnails/4.jpg)
4
Ola, I'm Norberto!
Norberto Leite
Technical Evangelist
Madrid, Spain
@nleite
http://www.mongodb.com/norberto
![Page 5: MongoDB and Spring - Two leaves of a same tree](https://reader030.fdocuments.us/reader030/viewer/2022032421/55a67ca01a28ab4f568b46ae/html5/thumbnails/5.jpg)
MongoDB
![Page 6: MongoDB and Spring - Two leaves of a same tree](https://reader030.fdocuments.us/reader030/viewer/2022032421/55a67ca01a28ab4f568b46ae/html5/thumbnails/6.jpg)
6
MongoDB
GENERAL PURPOSE DOCUMENT DATABASE OPEN-SOURCE
![Page 7: MongoDB and Spring - Two leaves of a same tree](https://reader030.fdocuments.us/reader030/viewer/2022032421/55a67ca01a28ab4f568b46ae/html5/thumbnails/7.jpg)
7
MONGODB FEATURES
JSON Document Model
with Dynamic Schemas
Auto-Sharding for
Horizontal Scalability
Text Search
Aggregation Framework
and MapReduce
Full, Flexible Index Support
and Rich Queries
Built-In Replication
for High Availability
Advanced Security
Large Media Storage
with GridFS
![Page 8: MongoDB and Spring - Two leaves of a same tree](https://reader030.fdocuments.us/reader030/viewer/2022032421/55a67ca01a28ab4f568b46ae/html5/thumbnails/8.jpg)
8
THE LARGEST ECOSYSTEM
9,000,000+MongoDB Downloads
250,000+Online Education Registrants
35,000+MongoDB User Group Members
35,000+MongoDB Management Service (MMS) Users
750+Technology and Services Partners
2,000+Customers Across All Industries
![Page 9: MongoDB and Spring - Two leaves of a same tree](https://reader030.fdocuments.us/reader030/viewer/2022032421/55a67ca01a28ab4f568b46ae/html5/thumbnails/9.jpg)
Document Data Model
Relational MongoDB
{
first_name: ‘Paul’,
surname: ‘Miller’,
city: ‘London’,
location:
[45.123,47.232],
cars: [
{ model: ‘Bentley’,
year: 1973,
value: 100000, … },
{ model: ‘Rolls Royce’,
year: 1965,
value: 330000, … }
]
}
![Page 10: MongoDB and Spring - Two leaves of a same tree](https://reader030.fdocuments.us/reader030/viewer/2022032421/55a67ca01a28ab4f568b46ae/html5/thumbnails/10.jpg)
10
Documents are Rich Data Structures
{
first_name: ‘Paul’,
surname: ‘Miller’,
cell: ‘+447557505611’
city: ‘London’,
location: [45.123,47.232],
Profession: [banking, finance, trader],
cars: [
{ model: ‘Bentley’,
year: 1973,
value: 100000, … },
{ model: ‘Rolls Royce’,
year: 1965,
value: 330000, … }
]
}
Fields can contain an array of sub-
documents
Fields
Typed field values
Fields can contain
arrays
![Page 11: MongoDB and Spring - Two leaves of a same tree](https://reader030.fdocuments.us/reader030/viewer/2022032421/55a67ca01a28ab4f568b46ae/html5/thumbnails/11.jpg)
11
Document Model Benefits
Agility and flexibility
Data model supports business change
Rapidly iterate to meet new requirements
Intuitive, natural data representation
Eliminates ORM layer
Developers are more productive
Reduces the need for joins, disk seeks
Programming is more simple
Performance delivered at scale
{
_id : ObjectId("4c4ba5e5e8aabf3"),
employee_name: "Dunham, Justin",
department : "Marketing",
title : "Product Manager, Web",
report_up: "Neray, Graham",
pay_band: “C",
benefits : [
{ type : "Health",
plan : "PPO Plus" },
{ type : "Dental",
plan : "Standard" }
]
}
![Page 12: MongoDB and Spring - Two leaves of a same tree](https://reader030.fdocuments.us/reader030/viewer/2022032421/55a67ca01a28ab4f568b46ae/html5/thumbnails/12.jpg)
Dynamic Schema
{
policyNum: 123,
type: auto,
customerId: abc,
payment: 899,
deductible: 500,
make: Taurus,
model: Ford,
VIN: 123ABC456,
}
{
policyNum: 456,
type: life,
customerId: efg,
payment: 240,
policyValue: 125000,
start: jan, 1995
end: jan, 2015
}
{
policyNum: 789,
type: home,
customerId: hij,
payment: 650,
deductible: 1000,
floodCoverage: No,
street: “10 Maple Lane”,
city: “Springfield”,
state: “Maryland”
}
![Page 13: MongoDB and Spring - Two leaves of a same tree](https://reader030.fdocuments.us/reader030/viewer/2022032421/55a67ca01a28ab4f568b46ae/html5/thumbnails/13.jpg)
Query Operators
Conditional Operators $all, $exists, $mod, $ne, $in, $nin, $nor, $or, $size,
$type
$lt, $lte, $gt, $gte
// find customers with any claims
> db.customers.find( {claims: {$exists: true }} )
// find customers matching a regular expression
> db.customers.find( {last: /^rog*/i } )
// count customers by city
> db.customers.find( {city: ‘Philadelphia’} ).count()
![Page 14: MongoDB and Spring - Two leaves of a same tree](https://reader030.fdocuments.us/reader030/viewer/2022032421/55a67ca01a28ab4f568b46ae/html5/thumbnails/14.jpg)
14
Indexes
// Index nested documents
> db.customers.ensureIndex({“policies.agent”:1} )
> db.customers.find({‘policies.agent’:’Fred’})
// geospatial index
> db.customers.ensureIndex({“property.location”: “2d” } )
> db.customers.find({“property.location” : { $near : [22,42] }} )
// text index
> db.customers.ensureIndex({“policies.notes”: “text” } )
![Page 15: MongoDB and Spring - Two leaves of a same tree](https://reader030.fdocuments.us/reader030/viewer/2022032421/55a67ca01a28ab4f568b46ae/html5/thumbnails/15.jpg)
MongoDB is Fully Featured
![Page 16: MongoDB and Spring - Two leaves of a same tree](https://reader030.fdocuments.us/reader030/viewer/2022032421/55a67ca01a28ab4f568b46ae/html5/thumbnails/16.jpg)
Spring Framework
Not just a framework!
![Page 17: MongoDB and Spring - Two leaves of a same tree](https://reader030.fdocuments.us/reader030/viewer/2022032421/55a67ca01a28ab4f568b46ae/html5/thumbnails/17.jpg)
17
Spring Framework
![Page 18: MongoDB and Spring - Two leaves of a same tree](https://reader030.fdocuments.us/reader030/viewer/2022032421/55a67ca01a28ab4f568b46ae/html5/thumbnails/18.jpg)
Spring Projects
![Page 19: MongoDB and Spring - Two leaves of a same tree](https://reader030.fdocuments.us/reader030/viewer/2022032421/55a67ca01a28ab4f568b46ae/html5/thumbnails/19.jpg)
Spring & MongoDB
![Page 20: MongoDB and Spring - Two leaves of a same tree](https://reader030.fdocuments.us/reader030/viewer/2022032421/55a67ca01a28ab4f568b46ae/html5/thumbnails/20.jpg)
Same Tree?
![Page 21: MongoDB and Spring - Two leaves of a same tree](https://reader030.fdocuments.us/reader030/viewer/2022032421/55a67ca01a28ab4f568b46ae/html5/thumbnails/21.jpg)
Let's put these 2 to work!
![Page 22: MongoDB and Spring - Two leaves of a same tree](https://reader030.fdocuments.us/reader030/viewer/2022032421/55a67ca01a28ab4f568b46ae/html5/thumbnails/22.jpg)
Build a "cool" App
![Page 23: MongoDB and Spring - Two leaves of a same tree](https://reader030.fdocuments.us/reader030/viewer/2022032421/55a67ca01a28ab4f568b46ae/html5/thumbnails/23.jpg)
![Page 24: MongoDB and Spring - Two leaves of a same tree](https://reader030.fdocuments.us/reader030/viewer/2022032421/55a67ca01a28ab4f568b46ae/html5/thumbnails/24.jpg)
24
Nice and simple
![Page 25: MongoDB and Spring - Two leaves of a same tree](https://reader030.fdocuments.us/reader030/viewer/2022032421/55a67ca01a28ab4f568b46ae/html5/thumbnails/25.jpg)
25
Video Catalog App
• All videos from our Education platform
– Yes, we have the coolest framework ever for
remote education!
https://university.mongodb.com/
![Page 26: MongoDB and Spring - Two leaves of a same tree](https://reader030.fdocuments.us/reader030/viewer/2022032421/55a67ca01a28ab4f568b46ae/html5/thumbnails/26.jpg)
26
Video Catalog App
• All videos from our Education platform
– Yes, we have the coolest framework ever for
remote education!
• Load information into MongoDB
• Allow people to vote on videos
• Find videos based on the metadata
• All using Spring Projects
– Let's also look into optimizations
![Page 27: MongoDB and Spring - Two leaves of a same tree](https://reader030.fdocuments.us/reader030/viewer/2022032421/55a67ca01a28ab4f568b46ae/html5/thumbnails/27.jpg)
27
Stack
MongoDB
DAL – Database Access Layer
demo.springio.batch REST API
![Page 28: MongoDB and Spring - Two leaves of a same tree](https://reader030.fdocuments.us/reader030/viewer/2022032421/55a67ca01a28ab4f568b46ae/html5/thumbnails/28.jpg)
CODE, CODE, CODE
![Page 29: MongoDB and Spring - Two leaves of a same tree](https://reader030.fdocuments.us/reader030/viewer/2022032421/55a67ca01a28ab4f568b46ae/html5/thumbnails/29.jpg)
29
DAL
• Decoupling Database
– Rule n1 on good Software Development
• Base Library
• Simple
![Page 30: MongoDB and Spring - Two leaves of a same tree](https://reader030.fdocuments.us/reader030/viewer/2022032421/55a67ca01a28ab4f568b46ae/html5/thumbnails/30.jpg)
30
Batch
• Batch Configuration Class
– reader()
– writer()
@Configuration
@EnableBatchProcessing
• ItemProcessor()
– Excellent way to do pre-aggregations,
computations…
![Page 31: MongoDB and Spring - Two leaves of a same tree](https://reader030.fdocuments.us/reader030/viewer/2022032421/55a67ca01a28ab4f568b46ae/html5/thumbnails/31.jpg)
31
Batch
• Things to look for
– chunk(chunkSize)
• Keep an eye on this value to optmise the loading
process
– writer()
• MongoDB bulk insert is here to help
![Page 32: MongoDB and Spring - Two leaves of a same tree](https://reader030.fdocuments.us/reader030/viewer/2022032421/55a67ca01a28ab4f568b46ae/html5/thumbnails/32.jpg)
32
REST API
@RestController
@RequestMapping("/…")
@EnableAutoConfiguration
… extends MongoRepository<T, I>
![Page 33: MongoDB and Spring - Two leaves of a same tree](https://reader030.fdocuments.us/reader030/viewer/2022032421/55a67ca01a28ab4f568b46ae/html5/thumbnails/33.jpg)
33
REST API
• Things to have in mind
– MongoRepository is "just" CRUD repository
• Need to autowire MongoTemplate to aggregate
– Updates
• Not a particular issue of SpringData
• General thing of ODM's
![Page 34: MongoDB and Spring - Two leaves of a same tree](https://reader030.fdocuments.us/reader030/viewer/2022032421/55a67ca01a28ab4f568b46ae/html5/thumbnails/34.jpg)
http://1.bp.blogspot.com/-H40bE-rJUqk/UXo3YatYjqI/AAAAAAAAAho/zjrQVk3WrNA/s1600/paella_03.jpg
Take Ways
![Page 35: MongoDB and Spring - Two leaves of a same tree](https://reader030.fdocuments.us/reader030/viewer/2022032421/55a67ca01a28ab4f568b46ae/html5/thumbnails/35.jpg)
35
Recap
• Spring has a lot of things out of the box that we do not
need to reinvent the all the time
• MongoDB can easily be integrated with existing Spring
based projects
• Performance is important
• Continuous Improvement is key!
![Page 36: MongoDB and Spring - Two leaves of a same tree](https://reader030.fdocuments.us/reader030/viewer/2022032421/55a67ca01a28ab4f568b46ae/html5/thumbnails/36.jpg)
36
Recap
• DOCUMENTATION!
– Awesome and complete on both projects!
![Page 37: MongoDB and Spring - Two leaves of a same tree](https://reader030.fdocuments.us/reader030/viewer/2022032421/55a67ca01a28ab4f568b46ae/html5/thumbnails/37.jpg)
We love enterprise!
![Page 38: MongoDB and Spring - Two leaves of a same tree](https://reader030.fdocuments.us/reader030/viewer/2022032421/55a67ca01a28ab4f568b46ae/html5/thumbnails/38.jpg)
38
MongoDB 3.0 is here!
![Page 39: MongoDB and Spring - Two leaves of a same tree](https://reader030.fdocuments.us/reader030/viewer/2022032421/55a67ca01a28ab4f568b46ae/html5/thumbnails/39.jpg)
http://www.humanandnatural.com/data/media/178/badan_jaran_desert_oasis_china.jpghttp://www.tinypm.com/blog/wp-content/uploads/2015/01/hammer.jpg
Fully Available!
3.0.2 https://www.mongodb.org/downloads
http://www.mongodb.com/norberto
![Page 40: MongoDB and Spring - Two leaves of a same tree](https://reader030.fdocuments.us/reader030/viewer/2022032421/55a67ca01a28ab4f568b46ae/html5/thumbnails/40.jpg)
40
Register now: mongodbworld.com
Early Bird Ends May 1!
Use Code NorbertoLeite for additional 25% Off*Come as a group of 3 or more – Save another 25%
![Page 41: MongoDB and Spring - Two leaves of a same tree](https://reader030.fdocuments.us/reader030/viewer/2022032421/55a67ca01a28ab4f568b46ae/html5/thumbnails/41.jpg)
We’re Always Looking for Top Talent
What are employees saying?
“Working with a group of individuals who you know will have your back is
one of the reasons I love working at MongoDB”
“Every day, we get to solve hard problems that make distributed databases
more accessible to developers all over the world”
“MongoDB lets you tackle real problems that affect hundreds of thousands
of users”
Visit us at www.mongodb.com/careers to see a full
list of opportunities or email your resume to
What are we hiring for?
• Technical Services Engineers (Dublin)
• Consulting Engineers (UK OR France)
• Solution Architects (France, Spain, Germany)
• Enterprise Account Executives ( France, Italy, UK, Germany)
• Corporate Account Executives (Dublin)
• Renewals Account Managers (Dublin)
![Page 42: MongoDB and Spring - Two leaves of a same tree](https://reader030.fdocuments.us/reader030/viewer/2022032421/55a67ca01a28ab4f568b46ae/html5/thumbnails/42.jpg)
Same Tree!!!
![Page 43: MongoDB and Spring - Two leaves of a same tree](https://reader030.fdocuments.us/reader030/viewer/2022032421/55a67ca01a28ab4f568b46ae/html5/thumbnails/43.jpg)
http://www.humanandnatural.com/data/media/178/badan_jaran_desert_oasis_china.jpg
Questions?
@nleite
![Page 44: MongoDB and Spring - Two leaves of a same tree](https://reader030.fdocuments.us/reader030/viewer/2022032421/55a67ca01a28ab4f568b46ae/html5/thumbnails/44.jpg)