Imitate join for NoSQL document database
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:
- Retrieve users with rating more than 1000
- 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).
精彩评论