我正在使用mongodb作为数据库存储.
我的网络应用程序必须收集用户响应.
用户响应是mongodb中的文档(或sql中的一行).文件长度约为10~200.
用户响应被分类(仅限一个类别).对于每个类别,用户响应的数量在100~5000之间.如果两个文档属于同一类别,则长度相同.(或者他们在sql中有相同的列)
可以通过管理员的请求动态创建/删除类别.
目前,我的数据结构是
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 }
..
Run Code Online (Sandbox Code Playgroud)
这是明智的决定吗?通过为每个类别分配一个集合,我担心会出现问题.如果我有很多收藏品会有一些性能问题吗?我应该合并我的集合并给用户响应一些标识符吗?
当然,答案取决于您的查询模式以及您正在查看的集合数量。在不了解更多信息的情况下,我怀疑您需要进行跨越许多响应集合的查询。
例如,如果每个userresponse
都有一个userId
字段,并且假设您想要获取特定用户的所有响应的日期排序列表。您需要循环遍历所有集合,查询每个集合,然后将结果合并到客户端代码中。显然,与索引集合中的单个简单查询/排序相比,这效率非常低UserResponse
。