Startup tech arsenal!
João Vazão Vasques
ABOUT ME
@JoaoVasques
@JoaoVasques
joao.l.v.vasques
jv@uniplaces.com
AGENDA
PART I - MongoDB
MongoDB topics
● Basic concepts
● Operations
● Data modeling
● Performance and tools
Basic concepts 1-2
● NoSQL
● No transactions
○ Eventual consistency
● No schema
○ Flexibility: code defines your schema
● ...
Basic concepts 2-2
Database
Table
Indexes
Columns
Row
Database
Collections
Indexes
Fields
Documents
Relational MongoDB
So we have...
Databases containing collections. A
collection is made up of documents.
Each document is made up of fields
Operations
● Document example (Uniplaces listing)
{
"title": "Uniplaces Mega mansion",
"rentable": false,
"location" : {
"...
Operations
Insert listings - insert
db.listings.insert( { title: "Erasmus Residence", rentable: true } )
db.listings.inser...
Operations
Update listings - update
Syntax: update( < query>, <update>, <options>)
Problem!
We want to make "Mansion" rent...
Operations
Update listings 2 -2
Reason: second parameter replaces the original. We replaced the entire
document with a new...
Search listings - find (1 - 2)
Syntax: find( < query>, <projection>)
Projection
db.listings.find( { title: "Uniplaces Mega...
Search listings - find (2 - 2)
Ordering (sort: -1 descending, 1 ascending)
db.listings.find({ $gte: { "apartment_details.b...
● MongoDB does not support Joins
● Embedded Documents
{
"title": "Uniplaces Mega mansion",
"bedrooms" : [
{
"price" : 500,...
Considerations:
● Geography
● System errors
○ ensure your backups can "survive"
● Production constraints
○ Schedule accord...
Approaches to backup MongoDB systems
● Binary database dumps
○ Small
○ Don't include index content and padding
○ Cannot re...
Backup and restore example
● Backup database
> mongodump -v -d test -o dump
● Restore database
> mongorestore -v --db test...
● Writes to primary (only)
○ A write is fully committed once it has replicated to a majority of servers
in the set
● Reads...
END OF PART I
Part II - Coding Time!
Part II - Coding Time!
Weapons we'll be using
● Web framework written in Scala & Java
● MVC paradigm
● Built on Akka
● Built in testing tools
● IDE support (Eclipse and...
MVC
Model - View - Controller
Anatomy of a Play! application
Coding samples
routing
Coding samples
template engine
Download the demo project on Github
● https://github.com/JoaoVasques/mongodb-workshop
Challenges:
● Fire Employee
● Search...
● engineering.linkedin.com
● blog.twitter.com/engineering
● facebook.com/Engineering
● engineering.foursquare.com
● nerds....
Thank you!
MongoDB and Play! Framework workshop
Upcoming SlideShare
Loading in...5
×

MongoDB and Play! Framework workshop

3,627

Published on

These slides were made for a 3 hour workshop integrate in the first edition of Startup Scholarship

Published in: Technology

Transcript of "MongoDB and Play! Framework workshop"

  1. 1. Startup tech arsenal! João Vazão Vasques
  2. 2. ABOUT ME @JoaoVasques @JoaoVasques joao.l.v.vasques jv@uniplaces.com
  3. 3. AGENDA
  4. 4. PART I - MongoDB
  5. 5. MongoDB topics ● Basic concepts ● Operations ● Data modeling ● Performance and tools
  6. 6. Basic concepts 1-2 ● NoSQL ● No transactions ○ Eventual consistency ● No schema ○ Flexibility: code defines your schema ● Scaling (Horizontal scaling) ● Document oriented ○ BJSON
  7. 7. Basic concepts 2-2 Database Table Indexes Columns Row Database Collections Indexes Fields Documents Relational MongoDB
  8. 8. So we have... Databases containing collections. A collection is made up of documents. Each document is made up of fields
  9. 9. Operations ● Document example (Uniplaces listing) { "title": "Uniplaces Mega mansion", "rentable": false, "location" : { "city" : "Lisboa", "coordinates" : { "longitude" : -9.145782599999961, "latitude" : 38.7234037 } }, "apartment_details" : { "bathrooms" : 2, "bedrooms" : 6, }, }
  10. 10. Operations Insert listings - insert db.listings.insert( { title: "Erasmus Residence", rentable: true } ) db.listings.insert( {title: "xpto", rentable: true, location: [{city: "lisbon", coordinates: {latitude: 0, longitude: 90} } ] } )
  11. 11. Operations Update listings - update Syntax: update( < query>, <update>, <options>) Problem! We want to make "Mansion" rentable. Solution (easy)! db.listings.update( { title: "Uniplaces Mega Mansion"}, {rentable: true } ) Search for Mega Mansion and...
  12. 12. Operations Update listings 2 -2 Reason: second parameter replaces the original. We replaced the entire document with a new one. Ups! Solution - $set Used when you want to change a value of one, or a few, fields db.listings.update( { title: "Uniplaces Mega Mansion"}, { $set: {rentable: true } } ) Other update modifiers: $inc, $unset, $push, $pop
  13. 13. Search listings - find (1 - 2) Syntax: find( < query>, <projection>) Projection db.listings.find( { title: "Uniplaces Mega mansion"}, {rentable: 1} ) Logical operators ($and) db.listings.find({ $and: [{ title: "Uniplaces Mega Mansion"}, {rentable: "false"}] }) Comparison operators ($gte) db.listings.find( { "apartment_details.bedrooms" : {$gte: 2 } }, { title: 1} ) Operations
  14. 14. Search listings - find (2 - 2) Ordering (sort: -1 descending, 1 ascending) db.listings.find({ $gte: { "apartment_details.bedrooms" : 2 }).sort ("apartment_details.bedrooms": -1) Paging (limit and skip) db.listings.find().limit(3).skip(1) Operations
  15. 15. ● MongoDB does not support Joins ● Embedded Documents { "title": "Uniplaces Mega mansion", "bedrooms" : [ { "price" : 500, "area": 25 }, { "price" : 700, "area": 30 }, ] } db.listings.find( {bedrooms: { $elemMatch: {price: { $gt: 20 }, area: 25} } }) Data modeling
  16. 16. Considerations: ● Geography ● System errors ○ ensure your backups can "survive" ● Production constraints ○ Schedule according to system usage ● Database configuration ○ Replication & Sharding Backups 1 -3
  17. 17. Approaches to backup MongoDB systems ● Binary database dumps ○ Small ○ Don't include index content and padding ○ Cannot reflect single moment in time ● Filesystem snapshots ○ Large backup sizes ○ Accurate ○ Require filesystem and OS tools ○ Can reflect a single moment in time ■ Note: in sharding all writes must be suspended Backups 2-3
  18. 18. Backup and restore example ● Backup database > mongodump -v -d test -o dump ● Restore database > mongorestore -v --db test dump Backups 3-3
  19. 19. ● Writes to primary (only) ○ A write is fully committed once it has replicated to a majority of servers in the set ● Reads to primary and secondary ● Consensus election in case of primary fail Replica Sets Secondary Secondary Primary W W W Secondary W
  20. 20. END OF PART I
  21. 21. Part II - Coding Time!
  22. 22. Part II - Coding Time! Weapons we'll be using
  23. 23. ● Web framework written in Scala & Java ● MVC paradigm ● Built on Akka ● Built in testing tools ● IDE support (Eclipse and IntelliJ IDEA) About Play!
  24. 24. MVC Model - View - Controller
  25. 25. Anatomy of a Play! application
  26. 26. Coding samples routing
  27. 27. Coding samples template engine
  28. 28. Download the demo project on Github ● https://github.com/JoaoVasques/mongodb-workshop Challenges: ● Fire Employee ● Search employee ● Create a backup of the database and restore it Hands on time!!!
  29. 29. ● engineering.linkedin.com ● blog.twitter.com/engineering ● facebook.com/Engineering ● engineering.foursquare.com ● nerds.airbnb.com Cool tech blogs
  30. 30. Thank you!
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×