I'm using mongodb as database storage.
my web app has to collect user responses.
a user response is a document in mongodb (or a row in sql). length of a document is about 10~200.
user responses are categorized(to only one category). for each category, number of user response is between 100~5000. if two document is in same category, the have same length. (or they have same columns in sql)
a category can be dynamically created/deleted by request of admins.
currently, my data structue is
category collection
{_id, 'name' : 'c1', 'somevalue' : '123'}
{_id, 'name' : 'c2', 'somevalue' : '23'}
{_id, 'name' : 'c3', 'somevalue' : '143'}
{_id, 'name' : 'c4', 'somevalue' : '153'}
...
'c1' collection
{ userresponse1 }
{ userresponse2 }
{ userresponse3 }
...
'c2' collection
{ userresponse1 }
{ userresponse2 }
{ userresponse3 }
...
'c3' collection
{ userresponse1 }
{ userresponse2 }
{ userresponse3 }
...
'cN' collection
{ userresponse1 }
{ userresponse2 }
{ userresponse3 }
..
Is this a wise decision? I'm worried about possibility of something going bad by assigning a collection for each category. will there be some performance issues if I have many collections? should I merge my collections and give the userresponses some identifiers instead?
Of course the answer depends on you query patterns and how many collections you're looking at having. Without knowing more, I would suspect that you would need to make queries that span many of the response collections.
For example if each userresponse
had a userId
field and suppose you wanted to get a date sorted list of all the responses for a specific user. You would need to loop over all the collections, query each, and combine the results in client code. Obviously this would be highly inefficient compared to a single simple query/sort in an indexed UserResponse
collection.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With