mongoDB: Why it should (not) replace your SQL database?

25 %
75 %
Information about mongoDB: Why it should (not) replace your SQL database?

Published on February 28, 2014

Author: mkowalski8



Can MongoDB replace SQL, one of the most popular database model in the world? Are we going to not use relational data models in future? The aim of the presentation is to present basic information about the noSQL and MongoDB. It tries to answer this questions by showing interesting possibilites of this noSQL database.

Maciej Miara, February 2014

• Non-relational database model • Easy horizontal scalability • Different data structures: - key-value store - key-value cache - object database - document store - graph store - wide-column store • Denormalization


• • •

Data structure • • • •

Data structure

Object ID • • ObjectId("507f191e810c19729de860ea") Seconds since the Unix epoch Machine identifier Process id Counter, starts with random value

Schema • • • •

Schema • • •

Schema Second query confirms, that mongo returns null, when attribute is not found in document

Querying embedded data • •

Querying embedded data

Capped collections • • • • db.createCollection("log", { capped : true, size : 5242880, max : 5000 }) • Good for logs or temporary data

Map-Reduce • • • • •

Map-Reduce • • • • • • •

Before Map-Reduce

Map-Reduce • • • • •

Map-Reduce • •

Indexes • • • • • •

Single field indexes Source: • May be used on embedded documents • Ascending or descending

Compound indexes • Index put on many fields • Sorting asc/desc for all fields Source:

Multikey indexes Source: • Index added for all items in array • Multikey compound indexes may hold only one compound index on array

Geospatial indexes • • • •

Geospatial queries • • • • • • •

Geospatial queries • • • • • • • •

Geospatial queries - examples Source:

Full text search • • • • • •

Full text search Source: Supported languages: danish, dutch, english, finnish, french, german, hungaria n, italian, norwegian, portuguese, norwegian, rommani an, russian, spanish, swedish, turkish

Sharding • • • •

Sharding Source:

Shard keys • • •

Shard keys – range keys Source:

Shard keys – hash keys Source:

Javascript driven • • • •

ACID • • • •

Transaction system • • •

Initial Let’s assume we have: Let’s start! Source:

Pending Beginning of operation. From now transaction is in progress Source:

Do what you need to do db.accounts.update({name: t.source, pendingTransactions: {$ne: t._id}}, {$inc: {balance: -t.value}, $push: {pendingTransactions: t._id}}) db.accounts.update({name: t.destination, pendingTransactions: {$ne: t._id}}, {$inc: {balance: t.value}, $push: {pendingTransactions: t._id}}) db.accounts.find() Perform operations that should be realized in one step. Here account’s balances are updated.

Committed All operations performed, so transaction is committed properly Source:

Remove pending Operations done, no longer pending Result: Source: { "_id" : ObjectId("4d7bc97fb8a04f5126961523"), "balance" : 900, "name" : "A", "pendingTransactions" : [ ] } { "_id" : ObjectId("4d7bc984b8a04f5126961524"), "balance" : 1100, "name" : "B", "pendingTransactions" : [ ] }

Done Change transaction state to done Source:

Failure reaction • • •

Rollback • •

Journaling • • • •

Write concern • • • • •

Unacknowledged Source:

Acknowledged Source:

Journal acknowledged Source:

Replica acknowledged Source:

Some people complain about Mongo, but…

…they just don’t know, why they chose it

• • • • • • „My friend from studies used it” „I was just curious” „Recommended by other company (in their project it worked well)” „Technical (!) client wanted it” „After all-night long party I decided to use it” „I heard that Microsoft/Google/NYT/(fill in any corpo you want) uses it”

Do NOT use Mongo, if you: • like joins • Need really transactional system • Have relational data • Want full ACID without any compromises

Any questions?

Add a comment

Related presentations

Presentación que realice en el Evento Nacional de Gobierno Abierto, realizado los ...

In this presentation we will describe our experience developing with a highly dyna...

Presentation to the LITA Forum 7th November 2014 Albuquerque, NM

Un recorrido por los cambios que nos generará el wearabletech en el futuro

Um paralelo entre as novidades & mercado em Wearable Computing e Tecnologias Assis...

Microsoft finally joins the smartwatch and fitness tracker game by introducing the...

Related pages

mongoDB: Why it should (not) replace your SQL database ...

... (not) replace your SQL database? ... Maciej Miara Slajdy:
Read more

Why You Should Never Use MongoDB « Sarah Mei

Why You Should Never Use MongoDB. ... I do not build database engines. ... I’m not saying that you should ditch away your RDBMS and use Riak instead, ...
Read more

Pros and Cons of using MongoDB instead of MS SQL Server ...

Pros and Cons of using MongoDB instead of MS SQL ... my MS Sql Server database to MongoDB. ... into your RAM. If not, then you should consider a ...
Read more

database - When would someone use MongoDB (or similar ...

... Why should I use document based database instead of ... MongoDB isn't meant to replace SQL. ... and when your querying needs are not too ...
Read more

Reasons for and against moving from SQL server to MongoDB

Reasons for and against moving from SQL server to MongoDB. ... In my opinion the format of your data should be ... Your database resembles your classes not ...
Read more

Which NoSQL database should I use to replace a ... - Quora

Which NoSQL database should I use to replace ... (although not as rich as SQL and certainly not similar) so your SQL ... to MongoDB queries. It should ...
Read more

Choosing a non-relational database. MySQL to MongoDB ...

Why we chose MongoDB. ... Our reasons for moving to MongoDB were not performance, ... How are you backing up your 800GB MongoDB database?
Read more

MongoDB for GIANT Ideas | MongoDB

MongoDB for GIANT Ideas ... Access and manipulate your data in sophisticated ways, ... NoSQL Database Explained. MongoDB Architecture Guide.
Read more

NoSQL Databases Explained | MongoDB

... may not improve the overall experience of your end ... NOSQL Databases; Types: One type (SQL database) ... SQL Server, Oracle Database: MongoDB, ...
Read more