2012-08-29 - NoSQL Bootcamp (Redis, RavenDB & MongoDB für .NET Entwickler)

Preview:

DESCRIPTION

Folienset von meinem eintägigen Workshop bei der DNUG Braunschweig. Blogeintrag: http://blog.johanneshoppe.de/2012/08/nosql-bootcamp-fazit/

Citation preview

{NoSQL-BootcamP}

{Intro}

case file 001

2002 2004 2006 2008 2010 2012

Daten

Scale-up

Scale-out

Schemafrei

Anforderungen

an ein verteiltes System

Consistency Konsistenz

Availability Verfügbarkeit

Partition

Tolerance Ausfalltoleranz

››

›››

››

“Drum prüfe,

wer sich ewig bindet.” Friedrich Schiller

›››

{Redis}

case file 002

› SET note1:title "Mittag"

› SET note1:message "nicht vergessen"

› KEYS note1:*

› GET note1:title

› DEL note1:title note1:message

http://bit.ly/ISv9f6

{RavenDB}

case file 003

›››

›››

››

›››

››

››

›››

››››

›››

››

›››

“While being RESTful is a goal of the

HTTP API, it is secondary to the goal of

exposing easy to use and powerful

functionality” Ayende Rahien on the HTTP API - http://ravendb.net/documentation/docs-http-api-restful

›››

C:\>curl -X GET http://localhost:8080/docs/Categories/1 -i HTTP/1.1 200 OK Content-Type: application/json; charset=utf-8 ETag: 00000000-0000-0200-0000-000000000004 { "Name" : "Normal Importance", "Color" : "green" }

Lucene Style var notes = session.Advanced .LuceneQuery<Note>() .Where(“Category:Important") .ToArray();

Classic Linq Style var notes = session .Query<Note>() .Where(n => n.Category == “Important") .ToArray();

{MongoDB}

case file 004

IBM’s IMS

Codd publishes relational model paper

in 1970

1966 1969 1970 1985 2000 2004 2007

Agile becoming more popular

1990’s 2009

CODASYL model published

Term “object-oriented database” appears

Brewer’s CAP born

Google BigTable

Amazon Dynamo

Apache Cassandra initial release

2008

MongoDB initial release

1973 1974

INGRES

SQL invented

1977

Oracle founded

10gen founded

NoSQL Movement

››

› use WebNote

› db.Notes.save( { Title: 'Mittag', Message: 'nicht vergessen‘ } );

› db.Notes.save

for(i=0; i<1000; i++) {

['quiz', 'essay', 'exam'].forEach(function(name) {

var score = Math.floor(Math.random() * 50) + 50;

db.scores.save({student: i, name: name, score: score});

});

}

db.scores.count();

› db.Notes.find();

› db.Notes.find({ Title: /Test/i });

› db.Notes.find( { "Categories.Color": "red"}).limit(1);

› db.Notes.update({Title: 'Test'}, {'$set': {Categories: []}});

› db.Notes.update({Title: 'Test'}, {'$push': {

Categories: {Color: 'Red'} }

});

› db.dropDatabase();

› db.Notes.drop();

› db.Notes.remove();

››

{PAUSE!}

Hands ON

case file 005

››

››

››

› use digg

› db.stories.findOne();

› use digg;

› db.people.update({name: 'Smith'},

{'$set': {interests: []}});

› db.people.update({name: 'Smith'}, {'$push': {interests: ['chess']}});

map = function() {

emit(this.user.name, {diggs: this.diggs, posts: 0});

}

reduce = function(key, values) {

var diggs = 0;

var posts = 0;

values.forEach(function(doc) {

diggs += doc.diggs;

posts += 1;

});

return {diggs: diggs, posts: posts};

}

db.stories.mapReduce(map, reduce, {out: 'digg_users'});

db.digg_users.find();

SIR,Yes,Sir!

SchemaDesign

case file 006

http://bsonspec.org

NULL NULL

NULL NULL

NULL

> db.shapes.find()

› { _id: "1", type: "c", area: 3.14, radius: 1}

› { _id: "2", type: "s", area: 4, length: 2}

› { _id: "3", type: "r", area: 10, length: 5, width: 2}

// Shapes mit radius > 0 finden

> db.shapes.find( { radius: { $gt: 0 } } )

blogs: { author : “Johannes", date : ISODate("2011-09-18T09:56:06.298Z"), comments : [ { author : “Klaus", date : ISODate("2011-09-19T09:56:06.298Z"), text : “toller Artikel" } ] }

blogs: { _id: 1000, author: “Johannes", date: ISODate("2011-09-18"), comments: [ {comment : 1)} ]}

comments : { _id : 1, blog: 1000, author : “Klaus", date : ISODate("2011-09-19")} > blog = db.blogs.find({ text: "Destination Moon" }); > db.comments.find( { blog: blog._id } );

// Jedes Produkt verlinkt die IDs der Kategorien

products: { _id: 10, name: "Destination Moon", category_ids: [ 20, 30 ] }

// Jedes Produkt verlinkt die IDs der Kategorien

products: { _id: 10, name: "Destination Moon", category_ids: [ 20, 30 ] }

// Jede Kategorie verlinkt die IDs der Produkte

categories:

{ _id: 20, name: "adventure",

product_ids: [ 10, 11, 12 ] }

categories:

{ _id: 21, name: "movie",

product_ids: [ 10 ] }

// Jedes Produkt verlinkt die IDs der Kategorien

products: { _id: 10, name: "Destination Moon", category_ids: [ 20, 30 ] }

// Jede Kategorie verlinkt die IDs der Produkte

categories:

{ _id: 20, name: "adventure",

product_ids: [ 10, 11, 12 ] }

categories:

{ _id: 21, name: "movie",

product_ids: [ 10 ] }

// Alle Kategorien für ein Produkt

> db.categories.find( { product_ids: 10 } )

// Jedes Produkt verlinkt die IDs der Kategorien

products: { _id: 10, name: "Destination Moon", category_ids: [ 20, 30 ] }

// Kategorien beinhalten keine Assoziationen

categories:

{ _id: 20,

name: "adventure"}

// Jedes Produkt verlinkt die IDs der Kategorien

products: { _id: 10, name: "Destination Moon", category_ids: [ 20, 30 ] }

// Kategorien beinhalten keine Assoziationen

categories:

{ _id: 20,

name: "adventure"}

// Alle Produkte für eine Kategorie

> db.products.find( { category_ids: 20 } )

// Jedes Produkt verlinkt die IDs der Kategorien

products: { _id: 10, name: "Destination Moon", category_ids: [ 20, 30 ] }

// Kategorien beinhalten keine Assoziationen

categories:

{ _id: 20,

name: "adventure"}

// Alle Produkte für eine Kategorie

> db.products.find( { category_ids: 20 } )

// Alle Kategorien für ein Produkt product

> product = db.products.find( { _id: some_id } )

> db.categories.find({_id: {$in : product.category_ids}})

Vielen Dank!

Recommended