educative.io

Additional table to store the relationships between users and photos

If we go with a NoSQL database, we need an additional table to store the relationships between users and photos to know who owns which photo. Let’s call this table ‘UserPhoto’. We also need to store the list of people a user follows. Let’s call it ‘UserFollow’. For both of these tables, we can use a wide-column datastore like Cassandra. For the ‘UserPhoto’ table, the ‘key’ would be ‘UserID’, and the ‘value’ would be the list of ‘PhotoIDs’ the user owns, stored in different columns. We will have a similar scheme for the ‘UserFollow’ table.

Is below what you mean when you say we create a UserPhoto table?

CREATE TABLE demo.UserPhoto ( UserID int, PhotoIDs list, PRIMARY KEY ( UserID) );

Then, we can do the following.

insert into demo.UserPhoto (UserID, PhotoIDs) values(1, []) ;

update demo.UserPhoto set PhotoIDs = PhotoIDs + [2] where UserID=1;

Hi @Dewey_Munoz

Yes, your approach seems correct.