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.
13. 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
16. ● 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
17. Considerations:
● Geography
● System errors
○ ensure your backups can "survive"
● Production constraints
○ Schedule according to system usage
● Database configuration
○ Replication & Sharding
Backups 1 -3
18. 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
19. Backup and restore example
● Backup database
> mongodump -v -d test -o dump
● Restore database
> mongorestore -v --db test dump
Backups 3-3
20. ● 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
24. ● Web framework written in Scala & Java
● MVC paradigm
● Built on Akka
● Built in testing tools
● IDE support (Eclipse and IntelliJ IDEA)
About Play!
29. 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!!!