Mongodb - many documents in one collection versus many collections

I use mongodb as a database repository.

my web application should collect user responses.

user response is a document in mongodb (or a string in sql). document length is about 10 ~ 200.

user responses are classified (only for one category). for each category, the number of user responses ranges from 100 to 5000. if two documents are in the same category, they have the same length. (or they have the same columns in sql)

a category can be dynamically created / deleted at the request of administrators.

currently my data structure

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 worry about the possibility of something bad, assigning a collection to each category. Will there be some performance issues if I have many collections? Should I combine my collections and give userresponses some identifiers instead?

+7
source share
1 answer

Of course, the answer depends on your query patterns and the number of collections you are looking for. Without knowing more, I would suspect that you would need to make queries covering many collections of answers.

For example, if each userresponse had a userId field and suggested that you want to get a list sorted by date of all the responses for a specific user. You will need to iterate over all the collections, request them and combine the results in the client code. Obviously, this would be extremely inefficient compared to one simple query / sort in the indexed userresponse collection.

+1
source

All Articles