how to look like a model? mongodb for rails apps

Post on 01-Nov-2014

260 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

@muc_rubyshift 11/09/2013

TRANSCRIPT

Anna Bulenkova@povergo

Software Developer @

JetBrains

MongoDB

How to look likea model?

A long time ago in a galaxy far, far away

Wow!It’s schema-free!

Say bye-bye to

• Normalization

Say bye-bye to

• Normalization

• Joins

Say bye-bye to

• Normalization

• Joins

• Design issues

Say bye-bye to

• Normalization

• Joins

• Design issues

• Transactions

Say bye-bye to

Something wrong?

Document =

{ key -> value }

Document-oriented!=

schema-free

Collection

BSON

{"hello": "world"}

"\x16\x00\x00\x00\x02hello\x00  \x06\x00\x00\x00world\x00\x00"

Outside MongoDB world?

MongoDB

•Win/OS X/*nix

•JavaScript

user = { name : "Foo" }db.testData.insert(user)

db.testData.find()

{ "_id" : ObjectId("51a7dc7b2cacf40b79990bf7"),

"name" : "Foo" }

•API

•Aggregation

•Indexes

•Replication

•Sharding

A little bit ofActiveRecord?

Mongoid

$ gem install mongoid

Configuration

Model

Associations

Embedded 1-1

Embedded 1-N

I want my relationship back!

Referenced 1-1

Referenced 1-N

Referenced N-N

# The band document.{

"_id" : ObjectId("4d3ed089fb60ab534684b7e9"),"tag_ids" : [ ObjectId("4d3ed089fb60ab534684b7f2") ]

}

# The tag document.{

"_id" : ObjectId("4d3ed089fb60ab534684b7f2"),"band_ids" : [ ObjectId("4d3ed089fb60ab534684b7e9") ]

}

$gem install mongoid_rails_migrations

It’s magical...

What a twist!

Where the hell are

transactions?

MongoDB does not have support for traditional locking or complex transactions with rollback. MongoDB aims to be lightweight, fast, and predictable in its performance. This is similar to the MySQL MyISAM autocommit model. By keeping transaction support extremely simple, MongoDB can provide greater performance especially for partitioned or replicated systems with a number of database server processes.

Document size limit

16MB

Global write lock

2.0pre

DB level lock2.2

No joins->

Many queries

Too many queries?

->Redesign

Indeed schemaless?

Journaling100ms

Data loss after

replication

Sharding delay

Unencrypted traffic

Side effects may include...

Problems working on 32-bit, large data storage problems, write falures, no error value return, sophicticated schema design, limited update operation, case sensitive queries, type sensitive fields, write

locks, replica sets restrictions, unexpected data loss, sharding size

limitations, no transactions, nausea, going back to RDBMS

It’s supported in

RubyMine

Any questions?

Thank you!

top related