This document discusses NoSQL databases and provides examples of different types. It begins by discussing motivations for NoSQL like performance, scalability, and flexibility over traditional relational databases. It then categorizes NoSQL databases as key-value stores like Redis and Tokyo Cabinet, column-oriented stores like BigTable and Cassandra, document-oriented stores like CouchDB and MongoDB, and graph databases like Neo4J. For each category it provides comparisons on attributes and examples using different languages.
67. require 'neo4j'
class Person
include Neo4j::NodeMixin
property :name, :mutant
index :name, :mutant
has_n :crushes
has_n :hookups
has_n :marriages
def initialize(name, mutant = true)
name = name
mutant = mutant
end
end
67
68. Neo4j::Transaction.run do
magneto = Person.new('Magneto')
esme = Person.new('Esme')
rogue = Person.new('Rogue')
magda = Person.new('Magda', false)
wasp = Person.new('Wasp', false)
magneto.crushes << wasp
magneto.hookups << rogue
magneto.marriages << magda
esme.crushes << magneto
rogue.hookups << magneto
magda.marriages << magneto
end
68
69. magneto = Person.find(:name => 'Magneto')
# Who likes Magneto?
magneto.relationships.incoming(:crushes).nodes
# Which non-mutants has Magneto dated?
magneto.hookups{ !mutant? }.to_a
69