Contenu connexe Similaire à Latinoware (20) Latinoware1. base de dados orientada a
documentos para aplicações Web
Kristina Chodorow
7. Key-Value Stores
Key Value
foo bar
x 123
ts 6:13:26 12/3/1945
data x9Fx44x1e
Tokyo Cabinet, Dynamo, MemcacheDB
10. Document-Oriented
{
date : Date(2007-05-07),
time : {
start : 9.25,
end : 10.25
}
sum : 0,
comments : ["task 1", "run 4", "testing module"]
}
vs.
20. A JavaScript Database
$ mongodb-linux-1.0/bin/mongo
MongoDB shell version: 1.0.0
url: test
connecting to: test
type "help" for help
>
21. JSON and BSON
Strict JSON types:
{
x : null, y : true, z : 123, w : "xyz",
a : { b : 1 }, c : [1, 2, 3]
}
Mongo JSON adds:
{
ts : new Date(),
query : /regex/ig,
_id : new ObjectId()
}
23. Collections
{
date : Date(2007-05-07),
time : {
start : 9.25,
end : 10.25
}
sum : 0,
comments : ["task 1", "run 4"]
}
26. Object Ids
an autogenerated primary key
"_id" : ObjectId("2fe3e4d892aa73234c910bed")
12 bytes:
2fe3e4d892aa73234c910bed
|------||----||--||----|
ts mac pid inc
28. Querying
posts = db.blog.find({
"author" : "Joe"})
commentsByFred = db.blog.find({
"comments.author" : "Fred"})
commentedByFred = db.blog.find({
"comments.author" : /fred/i})
31. …which gives us:
> db.blog.findOne()
{
_id : ObjectId("4ae06192213900000000745c"),
"title" : "First Post",
"content" : "Hello, world!"
"author" : {"name" : "Joe", "id" : 123}
"comments" : [{
"author" : "Fred",
"comment" : "Dumb post"
}]
}
32. $ instead of >, <, =, etc.
$gt, $gte, $lt, $lte, $eq, $neq, $exists,
$set, $mod, $where, $in, $nin, $inc
$push, $pull, $pop, $pushAll, $popAll
db.foo.bar.find({x : {$gt : 4}})
33. $where
db.blog.findOne({$where :
'this.y == (this.x + this.z)'});
Will work:
{"x" : 1, "y" : 4, "z" : 3}
{"x" : "hi", "y" : "hibye", "z" : "bye"}
Won’t work:
{"x" : 1, "y" : 1}
37. soliMAP
@trackmeet
FetLife
Dextify2
39. Logging
• insert/update/remove is fast
• Capped collections
• Schemaless
• $inc for counts
43. Storing Files
ObjectId fileId = new ObjectId();
fileObj = {
_id : fileId,
filename : "ggbridge.png",
user : "joe",
takenIn : "San Francisco"
}
chunkObj = {
fileId : fileId,
chunkNum : N
data : <binary data>
}
44. Aggregation
group =~ GROUP BY
Map/Reduce
db.runCommand({
mapreduce : <collection>,
map : <mapfunction>,
reduce : <reducefunction>
[, query : <query filter object>]
[, out : <outputcollectionname>]
[, keeptemp: <true|false>]
[, finalize : <finalizefunction>]
})
47. Thank you!
kristina@10gen.com
@kchodorow
@mongodb
irc.freenode.net#mongodb
www.mongodb.org