[erlang-questions] Wrap my mind around NoSQL (Mnesia)

Grzegorz Junka list1@REDACTED
Tue Nov 28 09:16:15 CET 2017


Hi,

You need to consider the impact that storing a list of user tags or urls 
in one filed can have on query times, i.e. {username, {urls, [tags]}} 
would require that you read and store the complete list of urls and tags 
when you need to add or remove one element. I would rather have a table 
with records {userId, url}. It will automatically have an index on 
userId. And then I would construct a select to query all urls for the 
given userId. Then a separate table {userName, userId}. Then a separate 
table {{userId, url}, tag} where {userId, url} is the key. I could also 
have {url, urlId} since multiple users can store the same url. That 
would save memory on having to remember the same url string multiple 
times. Then for any user I would have {userId, urlId} and {{userId, 
urlId}, tag}.

I hope that helps.

GrzegorzJ


On 24/11/2017 14:50, Silas wrote:
> Hi!
>
> (This is mainly a question about NoSQL conceptions.  If it is the 
> wrong place to ask, sorry for that and, please, let me know).
>
> After years using RDBMS (with structured and OO paradigms at the 
> programming language side) I'm diving into functional programming.  
> When choosing a programming language to practice, I immediately fell 
> in love with Erlang for this simplicity and beauty.
>
> After reading some documentation, some chapters of a book and trying 
> simple projects I decided to try a more complex project with Mnesia.  
> It is a social bookmarks website (something similar to what 
> del.icio.us is) where user can bookmark a URL and associate one or 
> more tags with it.  For instance, some could bookmark "erlang.org" to 
> tags "functionalprogramming", "programminglanguage" and others.  Users 
> also can query other users bookmarks, see what links are associated 
> with a tag and what tags are associated with a given bookmark.
>
> In my mind, an RDBMS is a perfect solution for this problem.  I'm 
> trying to fit it into the key -> value model, though.  My first 
> question is: is this possible or I'm just doing the wrong thing by 
> forcing the wrong solution?
>
> For what I understood, I need to get rid of normalization rules. So I 
> devised something more or less like that:
>
> User table: {username, {urls, [tags]}} % set
> UserTag table: {user, [tags]} % set
> TagUrls table: {tag, url} % bag
> TagUsers table: {tag, user} % bag
> Urlusers table: {url, user} %bag
> UrlTags table: {url, tag} %bag
>
> It is still a bit confusing where I'd use a set, a bag or an 
> ordered_set but I think you got the whole picture.
>
> Any help?
>
> Thanks!
>




More information about the erlang-questions mailing list