mongodb - javascript for your data
TRANSCRIPT
javascript for your data
MongoDB
Bridge the gap between key/val stores and traditional RDBMS
MongoDB
Bridge the gap between key/val stores and traditional RDBMS
MongoDB
the gaptable
MongoDB
the gaptable collection
MongoDB
collection
MongoDB
collectionBSON document
MongoDB
collectionBSON documenta set of fields
MongoDB
collectionBSON documenta set of fieldskey-value pair
MongoDB
collectionBSON documenta set of fieldskey-value pairkey: a name (string)
MongoDB
collectionBSON documenta set of fieldskey-value pairkey: a name (string)
val: any basic typestring, int, float, date, binary, array, document, ...
MongoDB
collectionBSON documentdb.users
db.products
db.barbieDollsYouHideFromYourFriends
MongoDB
collectionof BSON documents
queryable
MongoDB
the gaptable collection
SQL
MongoDB
the gaptable collection
SQL query objects
MongoDB
Query object
MongoDB
Query objectJSON-like query representation
MongoDB
Query objectJSON-like query representation
db.users.find({ 'lastname': 'Heckmann' });
MongoDB
Query object
{ 'lastname': 'Heckmann' }
MongoDB
Query object
{ 'lastname': 'Heckmann' }
could even be an array
MongoDB
Query object
{ 'lastname': 'Heckmann', 'body.odor': 'nasty', 'age': { $gt: 32 }, ...}
MongoDB
Query object
{ 'lastname': 'Heckmann', 'body.odor': 'nasty', 'age': { $gt: 32 }, ...}
MongoDB
Query object
{ 'lastname': 'Heckmann', 'body.odor': 'nasty', 'age': { $gt: 32 }, ...}
MongoDB
Query object
{ 'lastname': 'Heckmann', 'body.odor': 'nasty', 'age': { $gt: 32, $lt: 65 }, ...}
MongoDB
Query object
$gt$lt$ne$in$nin$all$not$size$exists more
MongoDB
Query object
RegExp too!
MongoDB
Query object
RegExp toodb.users.find({ 'lastname': /eckmann$/i });
MongoDB
Query object
Subsetsdb.users.find({ 'lastname': /eckmann$/i }, { 'age': true });
MongoDB
Query object
db.users .find({ 'lastname': /eckmann$/i }) .sort({ 'lastname': -1 }) .limit(10) .skip(10*(pageNumber - 1)) ;
MongoDB
Query object
db.users .find({ 'lastname': /eckmann$/i }) .sort({ 'lastname': -1 }) descending .limit(10) .skip(10*(pageNumber - 1)) ;
MongoDB
Query object
db.users .find({ 'lastname': /eckmann$/i }) .count() ;
MongoDB
no JOINs
MongoDB
no JOINs
less normalization
MongoDB
no JOINs
less normalization
embedded documents
MongoDB
embedded documents
MongoDB
embedded documents
{ name: 'aaron', scores: [ { total: 93, class: ObjectID } , { total: 46, class: ObjectID } , { total: 20, class: ObjectID } ]}
MongoDB
embedded documents
{ name: 'aaron', scores: [ { total: 93, class: ObjectID } , { total: 46, class: ObjectID } , { total: 20, class: ObjectID } ]}
think foreign keys
MongoDB
embedded documents
{ name: 'aaron', scores: [ { total: 93, class: ObjectID } , { total: 46, class: ObjectID } , { total: 20, class: ObjectID } ]}
{ _id: ObjectID, name: 'how to be a good neighbor', teacher: 'mr rogers'}
MongoDB
ObjectID
unique identifier of a document
each document has one
auto inserted if missing
MongoDB
Insertion and Updation
MongoDB
cheesy
Atomic Operations
MongoDB
$set$unset$inc$push$pushAll$pop$pull$pullAll$addToSet$rename
Atomic Ops
MongoDB
Indexing
MongoDB
Indexing
any property
into embedded documents
into arrays
MongoDB
Indexing
db.users.ensureIndex({ lastname: 1 })db.users.ensureIndex({ 'body.odor': 1 })db.users.ensureIndex({ 'body.odor': 1, age: 1 })
MongoDB
HTTP Interface
MongoDB
HTTP Interface
http://localhost:28017/
http://localhost:28017/database/collection/?limit=5
http://localhost:28017/database/collection/?filter_key=value
MongoDB
Document oriented
Schema-less
Rich queries
Full index support
Atomic operations
MapReduce
Auto-sharding / replication / GridFS
MongoDB
Mongoose
https://github.com/learnboost/mongoose/tree/1.0
Thank You
http://www.mongodb.orghttps://github.com/mongodbhttps://github.com/learnboost/mongoosehttps://github.com/christkv/node-mongodb-nativehttp://www.mongodb.org/display/DOCS/Production+Deployments
https://github.com/aheckmannhttp://twitter.com/#!/aaronheckmann