Dokumentowe bazy danych
Tomasz Wsuª
27.04.2011
Plan prezentacji
1
Wprowadzenie do dokumentowych baz danych
1
denicja
2
dokumenty
3
maªa ró»nica a cieszy
2
Lista baz
3
Przykªady baz
1
CouchDB
2
MongoDB
3
OrientDB
4
Koniec :)
Tomasz Wsuª
Dokumentowe bazy danych
Dokumentowe bazy danych nierelacyjne bazy danych operuj¡ce
na dokumentach
Wikipedia:
A document-oriented database is a computer program designed
for document-oriented applications. These systems may be
implemented as a layer above a relational database or an object
database.
Alex Popescu:
1
a data engine using a non-relational data model
2
a storage engine with knowledge about the data it is storing.
Basically the engine will be able to operate on inner values of
the records
3
an engine that can dene secondary indexes on non-key elds
and allows querying data based on these.
Tomasz Wsuª
Dokumentowe bazy danych
Dokumenty:
FirstName="Jonathan", Address="15 Wanamassa Point Road",
Children=[{Name:"Michael",Age:10}, {Name:"Jennifer", Age:8},
{Name:"Samantha", Age:5}, {Name:"Elena", Age:2}]
FirstName="Bob", Address="5 Oak St.", Hobby="sailing"
Tomasz Wsuª
Lista baz
Lotus Notes(1989), askSam, Apstrata, Datawasp, SimpleDB,
CRX, MUMPS Database(1966), UniVerse, UniData, Apache
Jackrabbit, Apache CouchDB, FleetDB, MongoDB, VMWare
GemFire Enterprise, OrientDB, RavenDB, Redis, Riak, StrokeDB,
Terrastore, ThruDB, Persevere, DBSlayer
Tomasz Wsuª
Apache CouchDB
akronim: cluster of unreliable commodity hardware
open source
Erlang (dawniej c++)
Apache License 2.0
http://couchdb.apache.org/
Tomasz Wsuª
Apache CouchDB - wprowadzenie
Django may be built for the Web, but CouchDB is built of the Web.
I've never seen software that so completely embraces the philosophies
behind HTTP. CouchDB makes Django look old-school in the same
way that Django makes ASP look outdated.
Jacob Kaplan-Moss, Django Developer
Dziaªanie MapReduce-like:
widoki
funkcje agreguj¡ce
ltry
REST api
Multi-Version Concurrency Control
rozproszona architektura z replikacj¡ multi-master
eventual consistency...
Tomasz Wsuª
Apache CouchDB - podstawy
Widok zbiór wybranych dokumentów
Funkcja map:
function(doc) {
if (doc.Type == "customer") {
emit(doc.LastName,
{FirstName: doc.FirstName, Address: doc.Address});
emit(doc.FirstName,
{LastName: doc.LastName, Address: doc.Address});
} }
Zliczanie wyst¡pie«:
reduce: function (doc) { emit(doc.FirstName, 1); }
reduce: function (key, values, rereduce) { return sum(values); }
Tomasz Wsuª
Apache CouchDB - podstawy
{
"total_rows":4,
"oset":0,
"rows": [
{"id":"64ACF01B05F53ACFEC48C062A5D01D89", "key":"Katz",
"value":{"FirstName":"Damien", "Address":"2407 Sawyer, Charlotte"} },
{ "id":"64ACF01B05F53ACFEC48C062A5D01D89", "key":"Damien",
"value":{"LastName":"Katz", "Address":"2407 Sawyer, Charlotte"} },
{ "id":"5D01D8964ACF01B05F53ACFEC48C062A", "key":"Kerr",
"value":{"FirstName":"Wayne", "Address":"123 Fake st., A and such"}
},
{ "id":"5D01D8964ACF01B05F53ACFEC48C062A", "key":"Wayne",
"value":{"LastName":"Kerr", "Address":"123 Fake st., A and such"} },
] }
Tomasz Wsuª
Apache CouchDB - przykªady
curl http://127.0.0.1:5984/
{"couchdb":"Welcome", "version":"1.0.1"}
curl -X PUT http://127.0.0.1:5984/wiki
{"ok":true}
curl -X GET http://127.0.0.1:5984/wiki
{"db_name":"wiki", "doc_count":0, "doc_del_count":0,
"update_seq":0, "purge_seq":0, "compact_running":false,
"disk_size":79, "instance_start_time":"1272453873691070",
"disk_format_version":5}
curl -X DELETE http://127.0.0.1:5984/wiki
{"ok":true}
Tomasz Wsuª
Apache CouchDB gotcha
Rysunek:
CAP wybierz 2
eventual consistency synchronizacja w dowolnym momencie
Tomasz Wsuª
MongoDB
humongous
open source
C++
GNU AGPL v3.0
http://www.mongodb.org/
Tomasz Wsuª
MongoDB - podstawy
Features:
UTF-8
Windows, Linux, OS X, Solaris
BSON Binary JSON Binary JavaScript Object Notation
Kursory dla wyników zapyta«
zapytania ad hoc
zagnie»d»anie dokumentów
indeksy (jest nawet indeks do danych geogracznych)
funkcje agreguj¡ce
dostarcza systemu plików
wykonywany po stronie serwera JavaScript
kolekcje cykliczne
replikacja: master-slave, replica-sets
automatyczny sharding
Tomasz Wsuª
MongoDB - przykªady
kolekcja users:
{ "username" : "bob", "address" : { "street" : "123 Main Street",
"city" : "Springeld", "state" : "NY" } }
db.users.nd({"address.state" : "NY"})
db.foo.nd({$where : function() { return this.x == this.y; }})
db.eval(function(name) { return "Hello, "+name; }, ["Joe"])
Hello, Joe
Tomasz Wsuª
MongoDB gotcha
dokumenty do 4MB
baza - plik mapowany na pami¦¢
w wersji 1.8: ... - journaling awaria=problem
nowy master ma zawsze racj¦, nawet je±li nie ma
Tomasz Wsuª
Bibliograa
myNoSQL http://nosql.mypopescu.com/
CouchDB http://couchdb.apache.org/
MongoDB http://www.mongodb.org/
http://en.wikipedia.org/wiki/Document-oriented_database
Tomasz Wsuª