Relational data query performance with nosql documents (mongodb, couchdb, riak, etc.)

To continue discussing my issue of modeling relational data using nosql , I read several related articles:

Nosql does not mean non-relational

Nosql Ecommerce Example

They seem to suggest that nosql can handle normalized relational data.

So, continue with the example that I had before, the CMS system, which has two types of data: the article and the authors, where the article has a link (by identifier) ​​to the author.

The following are the operations that the system must support:

  • Get the article by id with the author
  • Get all articles by a specific author
  • Find the first 10 articles with author (s) sorted by creation date

I would like to understand the effectiveness of these operations when comparing with the same operation if the same data was stored on an RDBMS. In particular, please indicate whether the operation uses MapReduce, requires multiple trips to the nosql repository (links) or pre-join

I would like to limit the discussion to a document-based nosql solution such as mongodb, couchdb and riak.

Change 1:

Spring -data project available for Riak and Mongodb

+5
source share
3 answers

MongoDB . , , . , , . , , MongoDB.

var article = db.articles.find({id: article_id}).limit(1);
var author = db.authors.find({id: article.author_id});

ORM/ODM , . , . , .

...

var author = db.authors.find({id: author_name}).limit(1);
var articles = db.articles.find({author_id: author.id});

, , .

var articles = db.articles.find({}).sort({created_at: 1}).limit(10);
var author_ids = articles.map(function(a) { return a.author_id });
var authors = db.authors.find({id: { '$in': authors_ids }});

, , , . mongo, , .

, . , mongo . .

, ... , . , , , db , , , . mongo , (100 200 ), , .

, , RDMS , . , CMS , ? , . dbs - RDMS .

, NoSQL!

+2

CouchDB , .:)

, , : .

CouchDB MapReduce, JavaScript ( Python, Ruby, Erlang ). MapReduce . .

CouchDB API HTTP, - HTTP- (GET, POST, PUT, DELETE) URL-. MapReduce ( JavaScript), URL-, .

1. id

- :

GET /db/{article_id}
GET /db/{author_id}

... {author_id} - , author_id .

2.

MapReduce

function (doc) {
  if (doc.type === 'article') {
    emit(doc.author_id, doc);
  }
}
GET /db/_design/cms/_view/articles_by_author?key="{author_id}"

... {author_id} - .

3. 10 ,

MapReduce

function (doc) {
  function arrayDateFromTimeStamp(ts) {
    var d = new Date(ts);
    return [d.getFullYear(), d.getMonth(), d.getDate(), d.getHours(), d.getMinutes(), d.getSeconds()];
  }

  var newdoc = doc;
  newdoc._id = doc.author_id;
  newdoc.created_at = arrayDateFromTimeStamp(doc.created_at);

  if (doc.type === 'article') {
    emit(newdoc.created_at, newdoc); 
  }
}

"" CouchDB, ?include_docs=true . "_id" emit ( ), include_docs=true , "_id". "_id" ( ) "_id" ( "author_id" ). 10 :

GET /db/_design/cms/_view/articles_by_date?descending=true&limit=10&include_docs=true

URL- 10 , :

{"rows":[
  { "id":"article_id",
    "key":[2011, 9, 3, 12, 5, 41],
    "value":{"_id":"author_id", "title":"..."},
    "doc":{"_id":"author_id", "name":"Author Name"}
  }
]}

, , , , .. .

(, CMS, ). , , CouchConf : http://www.slideshare.net/Couchbase/couchconfsfdesigningcouchbasedocuments

, , .

+5

id

SQL

  • 1
  • 2
  • 2
  • = +

MongoDB

  • 2
  • 2
  • 2
  • = +

SQL

  • 1
  • 1
  • N
  • = N

MongoDB

  • 1
  • 1
  • N
  • = N

10 (-),

SQL

  • 1
  • 2
  • 11 20 (, )
  • = 10 + 10

MongoDB

  • 2 (articles.find().sort().limit(10), authors.find({$in:[article_authors]})
  • 2
  • 11 20 (, )
  • = 10 + 1 10

MongoDB , . MongoDB ( ). , , , , . , .

MongoDB "" , ( " " ). , .

, . , .

+4
source

All Articles