SlideShare ist ein Scribd-Unternehmen logo
1 von 15
Rails meets
NoSql
Not Only SQL
Definition
● Schema-free.
● Easy replication support.
● Simple API.
● BASE (not ACID).
● Support a huge amount of data and more.
ACID:
Atomicity, Consistency, Isolation, Durability
BASE:
Basic Availability, Soft-state, Eventual
consistency
Differences
Relational and NoSQL data models are very
different. The relational model takes data and
separates it into many interrelated tables that
contain rows and columns. Tables reference
each other through foreign keys that are stored
in columns as well.
NoSQL databases have a very different model.
For example, a document-oriented NoSQL
database takes the data you want to store and
aggregates it into documents using the JSON
format.
types of nosql (currently 150)
1. Wide Column Store / Column Families
2. Document Store
3. Key Value / Tuple Store
4. Graph Databases
5. Multi-Model Databases
...
http://nosql-database.org/
http://www.couchbase.com/nosql-resources/what-is-no-sql
http://www.couchbase.com/nosql-resources/what-is-no-sql
So, when to NoSql?
http://kkovacs.eu/cassandra-vs-mongodb-vs-
couchdb-vs-redis
 Document Databases: Natural data modeling. Programmer friendly. Rapid development. Web
friendly, CRUD, dynamic queries maybe your data changes too much
 Graph Databases: Complicated graph problems, graph-style, rich or complex, interconnected
data.
 Key-Value Stores: Handles size well. Processing a constant stream of small reads and writes.
Fast, (most use cases: Cache), some times should fit mostly in memory.
 BigTable Clones: Handles size well. Stream massive write loads. High availability. Multiple-data
centers. MapReduce.
Rails meets NoSql (MongoDB)
rails new rails_meets_nosql --skip-active-record
in Gemfile
gem 'mongoid', '~> 4.0.1'
gem 'mongoid_paranoia', '~> 0.1.2'
gem 'moped', '~> 2.0.4'
gem 'bson_ext'
gem 'active_model_serializers', '~> 0.9.0'
rake db:drop # Drops all the collections for the database
rake db:mongoid:create_indexes # Create the indexes
rake db:mongoid:drop # Drops the default session
rake db:mongoid:purge # Drop all collections except the system collections
rake db:mongoid:remove_indexes # Remove the indexes
rake db:mongoid:remove_undefined_indexes # Remove indexes that exist in the database but
aren't specified on the models
rake db:seed # Load the seed data from db/seeds.rb
class Company
include Mongoid::Document
has_many :tickets
end
class Ticket
include Mongoid::Document
embeds_many :categories, as: :categorizable
belongs_to :company
belongs_to :developer
index({ 'categories.name': 1 }, unique: true, sparse: true)
index({ name: 1 }, unique: false)
end
class Developer
include Mongoid::Document
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# SCHEMA is in the models, not in schema.rb (No More Migrations)
## Database authenticatable
field :email, type: String
field :encrypted_password, type: String
...
end
Syntaxis
Person.create(first_name: "Heinrich", last_name: "Heine")
Person.in('tickets.categories.name' => ['fifis', 'VIP']).batch_size(500)
Person.find_by username: params[:username]
Concert.inc('available_tickets’: -1)
Person.tickets.push Ticket.new params[:ticket]
...
scope :has_active_discounts, -> { where('discounts.status' => true) }
default_scope -> { where(status: true).asc(:price) }
...
store_in collection: 'rock_singers', database: 'other'
http://mongoid.org/en/mongoid/docs/persistence.html

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Mongo db basics
Mongo db basicsMongo db basics
Mongo db basics
 
Scala with MongoDB
Scala with MongoDBScala with MongoDB
Scala with MongoDB
 
Lokijs
LokijsLokijs
Lokijs
 
MongoDB
MongoDBMongoDB
MongoDB
 
Mongo db nosql (1)
Mongo db nosql (1)Mongo db nosql (1)
Mongo db nosql (1)
 
MongoDB for Beginners
MongoDB for BeginnersMongoDB for Beginners
MongoDB for Beginners
 
Android Level 2
Android Level 2Android Level 2
Android Level 2
 
FITC presents: Mobile & offline data synchronization in Angular JS
FITC presents: Mobile & offline data synchronization in Angular JSFITC presents: Mobile & offline data synchronization in Angular JS
FITC presents: Mobile & offline data synchronization in Angular JS
 
Introduction to Elasticsearch
Introduction to ElasticsearchIntroduction to Elasticsearch
Introduction to Elasticsearch
 
Top 10 frameworks of node js
Top 10 frameworks of node jsTop 10 frameworks of node js
Top 10 frameworks of node js
 
Updating materialized views and caches using kafka
Updating materialized views and caches using kafkaUpdating materialized views and caches using kafka
Updating materialized views and caches using kafka
 
JSONpedia - Facilitating consumption of MediaWiki content
JSONpedia - Facilitating consumption of MediaWiki contentJSONpedia - Facilitating consumption of MediaWiki content
JSONpedia - Facilitating consumption of MediaWiki content
 
Mysql
MysqlMysql
Mysql
 
Php connectivitywithmysql
Php connectivitywithmysqlPhp connectivitywithmysql
Php connectivitywithmysql
 
Mongo db basics
Mongo db basicsMongo db basics
Mongo db basics
 
NoSQL
NoSQLNoSQL
NoSQL
 
Basics of MongoDB
Basics of MongoDB Basics of MongoDB
Basics of MongoDB
 
Mongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorials
Mongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorialsMongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorials
Mongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorials
 
NoSQL
NoSQLNoSQL
NoSQL
 
How do i Meet MongoDB
How do i Meet MongoDBHow do i Meet MongoDB
How do i Meet MongoDB
 

Andere mochten auch

Acontecimientos repetitivos y periódicos
Acontecimientos repetitivos y periódicosAcontecimientos repetitivos y periódicos
Acontecimientos repetitivos y periódicos
Giovanna Acuña Vasquez
 
Mmorpg c pve
Mmorpg c pveMmorpg c pve
Mmorpg c pve
linkperili1976
 

Andere mochten auch (9)

ΤΟ ΠΑΛΙΟ ΣΧΟΛΕΙΟ 2
ΤΟ ΠΑΛΙΟ ΣΧΟΛΕΙΟ 2ΤΟ ΠΑΛΙΟ ΣΧΟΛΕΙΟ 2
ΤΟ ΠΑΛΙΟ ΣΧΟΛΕΙΟ 2
 
Acontecimientos repetitivos y periódicos
Acontecimientos repetitivos y periódicosAcontecimientos repetitivos y periódicos
Acontecimientos repetitivos y periódicos
 
Recursos minerais
Recursos mineraisRecursos minerais
Recursos minerais
 
Information Management Summit 2014! Tapsa
Information Management Summit 2014! TapsaInformation Management Summit 2014! Tapsa
Information Management Summit 2014! Tapsa
 
Sales Tax 101: Questions To Consider Before Making A Critical Decision.
Sales Tax 101: Questions To Consider Before Making A Critical Decision.Sales Tax 101: Questions To Consider Before Making A Critical Decision.
Sales Tax 101: Questions To Consider Before Making A Critical Decision.
 
[LEDEN MEDIA | 레덴미디어] 중국 SNS/온라인 마케팅 제안서
[LEDEN MEDIA | 레덴미디어] 중국 SNS/온라인 마케팅 제안서[LEDEN MEDIA | 레덴미디어] 중국 SNS/온라인 마케팅 제안서
[LEDEN MEDIA | 레덴미디어] 중국 SNS/온라인 마케팅 제안서
 
Symbols (1)
Symbols (1)Symbols (1)
Symbols (1)
 
Mmorpg c pve
Mmorpg c pveMmorpg c pve
Mmorpg c pve
 
Rd cs steele_county
Rd cs steele_countyRd cs steele_county
Rd cs steele_county
 

Ähnlich wie Rails meets no sql

mongodb11 (1) (1).pptx
mongodb11 (1) (1).pptxmongodb11 (1) (1).pptx
mongodb11 (1) (1).pptx
RoopaR36
 

Ähnlich wie Rails meets no sql (20)

Mongo Bb - NoSQL tutorial
Mongo Bb - NoSQL tutorialMongo Bb - NoSQL tutorial
Mongo Bb - NoSQL tutorial
 
NoSql Databases
NoSql DatabasesNoSql Databases
NoSql Databases
 
Mongodb - NoSql Database
Mongodb - NoSql DatabaseMongodb - NoSql Database
Mongodb - NoSql Database
 
Mongo db
Mongo dbMongo db
Mongo db
 
JS App Architecture
JS App ArchitectureJS App Architecture
JS App Architecture
 
Non relational databases-no sql
Non relational databases-no sqlNon relational databases-no sql
Non relational databases-no sql
 
Unit II -BIG DATA ANALYTICS.docx
Unit II -BIG DATA ANALYTICS.docxUnit II -BIG DATA ANALYTICS.docx
Unit II -BIG DATA ANALYTICS.docx
 
NoSQL Basics and MongDB
NoSQL Basics and  MongDBNoSQL Basics and  MongDB
NoSQL Basics and MongDB
 
NOSQL and MongoDB Database
NOSQL and MongoDB DatabaseNOSQL and MongoDB Database
NOSQL and MongoDB Database
 
Polyglot Database - Linuxcon North America 2016
Polyglot Database - Linuxcon North America 2016Polyglot Database - Linuxcon North America 2016
Polyglot Database - Linuxcon North America 2016
 
SQL & NoSQL
SQL & NoSQLSQL & NoSQL
SQL & NoSQL
 
Introduction to NoSQL
Introduction to NoSQLIntroduction to NoSQL
Introduction to NoSQL
 
Unit 3 MongDB
Unit 3 MongDBUnit 3 MongDB
Unit 3 MongDB
 
NoSQL Databases
NoSQL DatabasesNoSQL Databases
NoSQL Databases
 
mongodb11 (1) (1).pptx
mongodb11 (1) (1).pptxmongodb11 (1) (1).pptx
mongodb11 (1) (1).pptx
 
Nosql seminar
Nosql seminarNosql seminar
Nosql seminar
 
DBVersity MongoDB Online Training Presentations
DBVersity MongoDB Online Training PresentationsDBVersity MongoDB Online Training Presentations
DBVersity MongoDB Online Training Presentations
 
NoSQL
NoSQLNoSQL
NoSQL
 
Big data technology unit 3
Big data technology unit 3Big data technology unit 3
Big data technology unit 3
 
Vskills Apache Cassandra sample material
Vskills Apache Cassandra sample materialVskills Apache Cassandra sample material
Vskills Apache Cassandra sample material
 

Kürzlich hochgeladen

introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
VishalKumarJha10
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 

Kürzlich hochgeladen (20)

The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions Presentation
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 

Rails meets no sql

  • 2. Definition ● Schema-free. ● Easy replication support. ● Simple API. ● BASE (not ACID). ● Support a huge amount of data and more.
  • 3. ACID: Atomicity, Consistency, Isolation, Durability BASE: Basic Availability, Soft-state, Eventual consistency
  • 4. Differences Relational and NoSQL data models are very different. The relational model takes data and separates it into many interrelated tables that contain rows and columns. Tables reference each other through foreign keys that are stored in columns as well.
  • 5. NoSQL databases have a very different model. For example, a document-oriented NoSQL database takes the data you want to store and aggregates it into documents using the JSON format.
  • 6. types of nosql (currently 150) 1. Wide Column Store / Column Families 2. Document Store 3. Key Value / Tuple Store 4. Graph Databases 5. Multi-Model Databases ... http://nosql-database.org/
  • 9. So, when to NoSql? http://kkovacs.eu/cassandra-vs-mongodb-vs- couchdb-vs-redis
  • 10.  Document Databases: Natural data modeling. Programmer friendly. Rapid development. Web friendly, CRUD, dynamic queries maybe your data changes too much  Graph Databases: Complicated graph problems, graph-style, rich or complex, interconnected data.  Key-Value Stores: Handles size well. Processing a constant stream of small reads and writes. Fast, (most use cases: Cache), some times should fit mostly in memory.  BigTable Clones: Handles size well. Stream massive write loads. High availability. Multiple-data centers. MapReduce.
  • 11. Rails meets NoSql (MongoDB) rails new rails_meets_nosql --skip-active-record in Gemfile gem 'mongoid', '~> 4.0.1' gem 'mongoid_paranoia', '~> 0.1.2' gem 'moped', '~> 2.0.4' gem 'bson_ext' gem 'active_model_serializers', '~> 0.9.0'
  • 12. rake db:drop # Drops all the collections for the database rake db:mongoid:create_indexes # Create the indexes rake db:mongoid:drop # Drops the default session rake db:mongoid:purge # Drop all collections except the system collections rake db:mongoid:remove_indexes # Remove the indexes rake db:mongoid:remove_undefined_indexes # Remove indexes that exist in the database but aren't specified on the models rake db:seed # Load the seed data from db/seeds.rb
  • 13. class Company include Mongoid::Document has_many :tickets end class Ticket include Mongoid::Document embeds_many :categories, as: :categorizable belongs_to :company belongs_to :developer index({ 'categories.name': 1 }, unique: true, sparse: true) index({ name: 1 }, unique: false) end
  • 14. class Developer include Mongoid::Document # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable # SCHEMA is in the models, not in schema.rb (No More Migrations) ## Database authenticatable field :email, type: String field :encrypted_password, type: String ... end
  • 15. Syntaxis Person.create(first_name: "Heinrich", last_name: "Heine") Person.in('tickets.categories.name' => ['fifis', 'VIP']).batch_size(500) Person.find_by username: params[:username] Concert.inc('available_tickets’: -1) Person.tickets.push Ticket.new params[:ticket] ... scope :has_active_discounts, -> { where('discounts.status' => true) } default_scope -> { where(status: true).asc(:price) } ... store_in collection: 'rock_singers', database: 'other' http://mongoid.org/en/mongoid/docs/persistence.html