Calculating the number of matching elements in documents


I am calculating the number of matching elements in pairs of documents in a collection. Fields are mostly categorical like professional interests, hobbies etc. I am thinking about keeping each category for a particular parameter as a separate field: if possible hobbies a user can choose from are soccer, baseball, skating than each user would have either 0 or 1 corresponding to each of them depending on whether they chose it as their hobby.

However, I am not sure about how to best store and compare some custom categories a user can manually enter, i.e. something in the “other” field. There could be any number of unique values, and each user can have multiple of them. Comparing arrays of items for each user feels suboptimal.

Any suggestions on how to do it right? Thank you!

Hi @plaggy,

Just to make sure I understand the problem you’re working on, are you trying to find how many of your users have certain hobbies? Or how many common hobbies two given users may have?

Also, when you say “any number of unique values”, are you using a unique index constraint to enforce that on the entire field, or do you mean something else?