2. What is "NoSQL"?
Complement, not replace, traditional relational databases
Different ways to store large quantities of denormalized
data
Key/Value = Redis, Riak
Tabular / "Big Table" = HBase, Cassandra
Document = MongoDB, CouchDB
No schema
Map/Reduce
Easy scalability
3. RDMS is just fine
YES!
When you must guarantee transactional/ACID behavior
When you must have strict constraints
But...not when these are more important
Faster queries
Horizontal scalability
Flexible design
7. Beware the N+1 problem does lurk
Having no method for joining
means we could have a lot of
queries on our hands if we do
establish a large one-to-many
relationship outside of our
"User" document
8. MongoDB, BSON, and You
MongoDB does "document" storage
JSON is a popular lightweight data structure
BSON is a binary encoded serialized JSON document
Programming languages map to-from BSON easily
Most languages have a dictionary or hash
10. How do I install MongoDB?
Go to http://www.mongodb.org/downloads
For Macs I'd recommend using Brew
brew install mongodb
For Linux, it depends on your distro
Pre-Packaged for Ubuntu/Debian
Pre-Packaged for CentOS/Fedora/Redhat
Good old source!
There are even installers for WinDoze
11. The './mongo' Console
MongoDB has a console very much like MySQL
>./mongo
> help
OK, how do I query to find my stuff?
12. The new query language you already know
MongoDB
<3
JSON
<3
JavaScript
13. SQL to Mongo Operations
SQL Statement Mongo Query Language Statement
CREATE TABLE USERS (a Number, b Number) implicit. MongoDB is "lazy".
INSERT INTO USERS VALUES(1,1) db.users.insert({a:1,b:1})db.users.find({}, {a:1,b:1})
SELECT a,b FROM users
SELECT a,b FROM users WHERE db.users.find({age:33}, {a:1,b:1})db.users.find({'age':
age=33SELECT * FROM users WHERE {$gt:33}})})db.users.find({name:/Joe/})
age>33SELECT * FROM users WHERE name
LIKE "%Joe%"
EXPLAIN SELECT * FROM users WHERE z=3SELECT db.users.find({z:3}).explain()db.users.distinct('last_name') db.
DISTINCT last_name FROM users UPDATE users SET users.update({b:'q'}, {$set:{a:1}}, false, true)
a=1 WHERE b='q'
DELETE FROM users WHERE z="abc" db.users.remove({z:'abc'});