14. Documents
Can store JSON types - strings, integers, floats, doubles,
arrays, objects, null, boolean
Special types - data, object id, binary, regex, and code
16mb hard limit
Every document can have different keys
23. > db.posts.findOne()
{
_id : ObjectId(‘8dfhosiahdf89sf9sd’),
title : “Hello world!”,
body : “Lorem ipsum...”,
author : {
name : “Alex”
}
}
> db.posts.find().limit(1)
> db.posts.find().limit(1).pretty()
24. > db.posts.insert({
title : “Another post”,
body : “Dolor sit amet...”
author : {
name : “Alex”
},
tags : [“PHP”, “MongoDB”]
})
> db.posts.save({...})
25. SELECT * FROM posts WHERE title =
“Another Post”
db.posts.find({title : “Another Post”})
{ _id : ObjectId(‘8dfhosiahdf89sf9sd’),
title : “Another post”, body : “Dolor sit
amet...”, author : {name : “Alex”}, tags :
[“PHP”, “MongoDB”] }
26. SELECT body FROM posts WHERE title =
“Another Post”
db.posts.find({title : “Another Post”},
{body : 1})
{ _id : ObjectId(‘8dfhosiahdf89sf9sd’),
body : “Dolor sit amet...” }
30. db.people.insert({name : “Alex”, age: 22, sex :
“Male”})
db.people.insert({name : “Nick”, age: 24, sex :
“Male”})
db.people.insert({name : “Steph”, age: 28, sex :
“Female”})
31. SELECT * FROM people WHERE age > 22
db.people.find({age : {$gt : 22}})
32. SELECT * FROM people WHERE age <= 25
db.people.find({age : {$lte : 25}})
33. $gt Greater than
$gte Greater than or equal to
$lt Less than
$lte Less than or equal to
$ne Not equal to
$in In array
$nin Not in array
34. $mod Mod operator
$all Matches all values in array
$size Size of array
$exists Key in array exists
$type Matches data type
$not Negates value of another operator
$or Where == OR ==
$nor Where !== AND !==
43. $inc Increment value
$set Set field to value
$unset Delete field
$push Appends field to value (if field is an
array otherwise works like $set)
$pushAll Multiple $push
$addToSet $push only if not exists
$pop Array pop
$pull Removes all occurrences of value
44. $pull Removes all occurrences of
value
$pullAll Pull all values
$rename Rename field
$bit Bitwise update of field
51. Double query
+ Don’t need to worry about hard limit
+ Much easier querying
+/- Double query
52. Some untruths
“MongoDB is not single server durable”
“MongoDB will lose my data because it is not ACID
compliant”
“I need 12 terabytes of RAM to use MongoDB”
“MongoDB is just CouchDB but with more marketing weight
behind it”
53. How we use MongoDB
AD
Blackboard
BP Nucleus
CMIS
Estates
54. How we use MongoDB
.xml
.json
.csv
.rdfxml
Nucleus .tutle
.n3
.ntriples
.kml
55. Appropriate Use Caes
Logs
Data warehousing / archiving
Location based apps (Foursquare / o2 Priorities)
Ecommerce (with RDBMS for billing)
Gaming
Real time stats
56. Less well suited use cases
Tractional systems
Epic join based query based systems
57. CodeIgniter and MongoDB
CodeIgniter library - http://lncn.eu/fmy5
Follows the query builder (active record) database library
Version 2.0 almost finished
59. CodeIgniter Library v2.0
Multiple database support
Epic code clean up
Remove CodeIgniter-only functions so can be used in other
frameworks or vanilla PHP
Supports new MongoDB 2.0+ features
60. Where can I find out more?
mongodb.com
groups.google.com/group/mongodb-user
irc://irc.freenode.net/#mongodb
blog.boxedice.com
cookbook.mongodb.com
10gen.com/events