javascript for your datajavascript 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 gap
● table
MongoDB
the gap
● table → collection
MongoDB
collection
MongoDB
collection
● BSON document
MongoDB
collection
● BSON document
● a set of fields
MongoDB
collection
● BSON document
● a set of fields
– key-value pair
MongoDB
collection
● BSON document
● a set of fields
– key-value pair
● key: a name (string)
MongoDB
collection
● BSON document
● a set of fields
– key-value pair
● key: a name (string)
● val: any basic type
– strin...
MongoDB
collection
● of BSON documents
● queryable
MongoDB
the gap
● table → collection
● SQL
MongoDB
the gap
● table → collection
● SQL → query objects
MongoDB
Query object
MongoDB
Query object
● JSON-like query representation
MongoDB
Query object
● JSON-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 too
db.users.find({ 'lastname': /eckmann$/i });
MongoDB
Query object
Subsets
db.users.find({ 'lastname': /eckmann$/i }, { 'age': true });
MongoDB
Query object
db.users
.find({ 'lastname': /eckmann$/i })
.sort({ 'lastname': -1 })
.limit(10)
.skip(10*(pageNumber...
MongoDB
Query object
db.users
.find({ 'lastname': /eckmann$/i })
.sort({ 'lastname': -1 }) ← descending
.limit(10)
.skip(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 }
, {...
MongoDB
embedded documents
{ name: 'aaron'
, scores:
[ { total: 93, class: ObjectID }
, { total: 46, class: ObjectID }
, {...
MongoDB
embedded documents
{ name: 'aaron'
, scores:
[ { total: 93, class: ObjectID }
, { total: 46, class: ObjectID }
, {...
MongoDB
ObjectID
● unique identifier of a document
● each document has one
● auto inserted if missing
MongoDB
Insertion and UpdationInsertion and Updation
MongoDB
cheesy
Atomic OperationsAtomic Operations
MongoDB
$set
$unset
$inc
$push
$pushAll
$pop
$pull
$pullAll
$addToSet
$rename
Atomic Ops
MongoDB
IndexingIndexing
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({ 'bo...
MongoDB
HTTP InterfaceHTTP Interface
MongoDB
HTTP Interface
● http://localhost:28017/
● http://localhost:28017/database/collection/?limit=5
● http://localhost:...
MongoDB
● Document oriented
● Schema-less
● Rich queries
● Full index support
● Atomic operations
● MapReduce
● Auto-shard...
MongoDB
Mongoose
● https://github.com/learnboost/mongoose/tree/1.0
Thank You
http://www.mongodb.org
https://github.com/mongodb
https://github.com/learnboost/mongoose
https://github.com/chri...
Upcoming SlideShare
Loading in...5
×

MongoDB - Javascript for your Data

1,171

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,171
On Slideshare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
7
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Transcript of "MongoDB - Javascript for your Data"

  1. 1. javascript for your datajavascript for your data
  2. 2. MongoDB Bridge the gap between key/val stores and traditional RDBMS
  3. 3. MongoDB Bridge the gap between key/val stores and traditional RDBMS
  4. 4. MongoDB the gap ● table
  5. 5. MongoDB the gap ● table → collection
  6. 6. MongoDB collection
  7. 7. MongoDB collection ● BSON document
  8. 8. MongoDB collection ● BSON document ● a set of fields
  9. 9. MongoDB collection ● BSON document ● a set of fields – key-value pair
  10. 10. MongoDB collection ● BSON document ● a set of fields – key-value pair ● key: a name (string)
  11. 11. MongoDB collection ● BSON document ● a set of fields – key-value pair ● key: a name (string) ● val: any basic type – string, int, float, date, binary, array, document, ...
  12. 12. MongoDB collection ● of BSON documents ● queryable
  13. 13. MongoDB the gap ● table → collection ● SQL
  14. 14. MongoDB the gap ● table → collection ● SQL → query objects
  15. 15. MongoDB Query object
  16. 16. MongoDB Query object ● JSON-like query representation
  17. 17. MongoDB Query object ● JSON-like query representation ● db.users.find({ 'lastname': 'Heckmann' });
  18. 18. MongoDB Query object { 'lastname': 'Heckmann' }
  19. 19. MongoDB Query object { 'lastname': 'Heckmann' } could even be an array
  20. 20. MongoDB Query object { 'lastname': 'Heckmann' , 'body.odor': 'nasty' , 'age': { $gt: 32 } , ... }
  21. 21. MongoDB Query object { 'lastname': 'Heckmann' , 'body.odor': 'nasty' , 'age': { $gt: 32 } , ... }
  22. 22. MongoDB Query object { 'lastname': 'Heckmann' , 'body.odor': 'nasty' , 'age': { $gt: 32 } , ... }
  23. 23. MongoDB Query object { 'lastname': 'Heckmann' , 'body.odor': 'nasty' , 'age': { $gt: 32, $lt: 65 } , ... }
  24. 24. MongoDB Query object $gt $lt $ne $in $nin $all $not $size $exists … more
  25. 25. MongoDB Query object RegExp too!
  26. 26. MongoDB Query object RegExp too db.users.find({ 'lastname': /eckmann$/i });
  27. 27. MongoDB Query object Subsets db.users.find({ 'lastname': /eckmann$/i }, { 'age': true });
  28. 28. MongoDB Query object db.users .find({ 'lastname': /eckmann$/i }) .sort({ 'lastname': -1 }) .limit(10) .skip(10*(pageNumber - 1)) ;
  29. 29. MongoDB Query object db.users .find({ 'lastname': /eckmann$/i }) .sort({ 'lastname': -1 }) ← descending .limit(10) .skip(10*(pageNumber - 1)) ;
  30. 30. MongoDB Query object db.users .find({ 'lastname': /eckmann$/i }) .count() ;
  31. 31. MongoDB ● no JOINs
  32. 32. MongoDB ● no JOINs ● less normalization
  33. 33. MongoDB ● no JOINs ● less normalization ● embedded documents
  34. 34. MongoDB embedded documents
  35. 35. MongoDB embedded documents { name: 'aaron' , scores: [ { total: 93, class: ObjectID } , { total: 46, class: ObjectID } , { total: 20, class: ObjectID } ] }
  36. 36. MongoDB embedded documents { name: 'aaron' , scores: [ { total: 93, class: ObjectID } , { total: 46, class: ObjectID } , { total: 20, class: ObjectID } ] } think foreign keys
  37. 37. 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' }
  38. 38. MongoDB ObjectID ● unique identifier of a document ● each document has one ● auto inserted if missing
  39. 39. MongoDB Insertion and UpdationInsertion and Updation
  40. 40. MongoDB
  41. 41. cheesy
  42. 42. Atomic OperationsAtomic Operations
  43. 43. MongoDB $set $unset $inc $push $pushAll $pop $pull $pullAll $addToSet $rename Atomic Ops
  44. 44. MongoDB IndexingIndexing
  45. 45. MongoDB Indexing ● any property ● into embedded documents ● into arrays
  46. 46. MongoDB Indexing db.users.ensureIndex({ lastname: 1 }) db.users.ensureIndex({ 'body.odor': 1 }) db.users.ensureIndex({ 'body.odor': 1, age: 1 })
  47. 47. MongoDB HTTP InterfaceHTTP Interface
  48. 48. MongoDB HTTP Interface ● http://localhost:28017/ ● http://localhost:28017/database/collection/?limit=5 ● http://localhost:28017/database/collection/?filter_key=value
  49. 49. MongoDB ● Document oriented ● Schema-less ● Rich queries ● Full index support ● Atomic operations ● MapReduce ● Auto-sharding / replication / GridFS
  50. 50. MongoDB Mongoose ● https://github.com/learnboost/mongoose/tree/1.0
  51. 51. Thank You http://www.mongodb.org https://github.com/mongodb https://github.com/learnboost/mongoose https://github.com/christkv/node-mongodb-native http://www.mongodb.org/display/DOCS/Production+Deployments https://github.com/aheckmann http://twitter.com/#!/aaronheckmann

×