Database Reference
In-Depth Information
So, here is a real-world problem that will allow you to showcase your
NoSQL modeling skills to the fullest. If you are teaching, you can make
this a graduation project.
Imagine that you need to store and retrieve all the comments for a video.
However, remember that you will also need all the comments for a given user.
Think about a design for this problem and then come back to take a look at our
proposed answer.
Here's our answer to this problem.
We will need two index tables, as follows:
// Comments as a many-to-many
// Looking from the video side to many users
CREATE TABLE comments_by_video (
videoid uuid,
username varchar,
comment_ts timestamp,
comment varchar,
PRIMARY KEY (videoid,comment_ts,username)
) WITH CLUSTERING ORDER BY (comment_ts DESC, username ASC);
// looking from the user side to many videos
CREATE TABLE comments_by_user (
username varchar,
videoid uuid,
comment_ts timestamp,
comment varchar,
PRIMARY KEY (username,comment_ts,videoid)
) WITH CLUSTERING ORDER BY (comment_ts DESC, videoid ASC);
This should create an Aha! moment, where a light bulb comes up (if it did not come
up before), and you might heave a sigh of satisfaction.
Now, let's solidify this in a lab.
To generate input data, run the following script:
./generate_comment_indices.sh 5 10
 
Search WWH ::




Custom Search