Pergunta

I'm building an application on node.js that has users and products in a many-to-many relationship (one user has many products and the same product might belong to multiple users). Each user has also location info.

Mostly I need to do a lot of writes on the user first visit (a few writes on the following visits) and then I need to match users that, for instance, have the most number of products in common and return that same products in common. I may also want to match users by location (or sort them by matching location)

I'm using postgres right now but I think I would be better of doing mongo in the long run. Problem is that I never worked on NOSQL DB (no fears ;) )

The question is, is the following "schema" suited for the described above?

[user]{
_id
name
age
[location]{
           streep
           town
           country
          }
}  

[products]{
_id
name
color
[users]{
        user_id_1
        user_id_2
        user_id_3
        }
}

I think, because of the requirements, I'm better of this way than with embeding. Am I right? Do you think I should store the products_id in the user document?

Thanks!!

Foi útil?

Solução

Your data seems quite relational to me. I would not see a great advantage for MongoDB or NoSQL solutions. They work well for document-based solutions that aren't relational.

I would get some data if you're having problems with scaling or performance. Don't assume a solution until you know what the root cause is. It could be node.js - who knows? Some people don't care much for it.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top