开发者

Imitate join for NoSQL document database

开发者 https://www.devze.com 2023-04-12 18:45 出处:网络
Are there any workarounds to execute join-like query with NoSQL document database? Example: We need to select last month articles by users with rating more than thousand.

Are there any workarounds to execute join-like query with NoSQL document database?

Example: We need to select last month articles by users with rating more than thousand. SQL solution is

SELECT a.* FROM Articles as a
INNER JOIN Users as u ON a.UserId = u.Id
WHERE a.Date > (Now - Month) AND u.Rating > 1000

I can imagine several NoSQL solutions. First is two queries solution:

  1. Retrieve users with rating more than 1000
  2. Retrieve last month articles for t开发者_开发问答hese users

I don't like it as I have to make two queries and I have to retrieve all users with rating > 1000 (what if I have 1kk of users?)

The other NoSQL solution which comes to my mind is denormalization. But I am not big fan of it. I would be not against of putting comments collection to post entity (because comments belong to post), but I don't like to put user inside article or articles inside user.

Are there any other solutions?


You can do that using Multi Maps / Reduce indexes with RavenDB. See here.


RavenDB Multi Maps handles this scenarios very well:

http://ayende.com/blog/89089/ravendb-multi-maps-reduce-indexes


Another solution may be playOrm where you can partition a table and select and join on partitions. IT is basically like hibernate with JQL and all except you query into partitions. Perhaps if you partition by month, you can run a simple old school select query on that partition and join it with something else. noSql now seems to have joins through playOrm ;). It of course does not do joins on HUGE tables. The PARTITION needs to be comparative size to RDBMS table sizes when doing joins....The table size can be infinite(ie. you have infinite partitions).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号