我是蒙哥大的新手。需要了解使用>5gb相关数据获取一个文档的性能问题。
我的文件结构:
{
_id:100,
question_id:200,
analyze_data:[
{
date:20-01-1920,
store_id:50,
user_id:6,
},
.....,
hundreds of thousands of records here
.....,
{
date:20-01-2015,
store_id:6000,
user_id:600000,
},
(nth number)
],
graph_data:[
{
graph_id:5
date:20-01-1920,
store_id:50,
user_id:6,
},
.....,
hundreds of thousands of records here
.....,
{
date:20-01-2015,
store_id:10000,
user_id:400000,
},
(nth number)
]
}我有这种类型的文件在我的集合,我必须过滤analyze_data和graph_data根据date,store_id,user_id。
过滤后,我需要做一些计算和重构我的数组。
{
_id:100,
question_id:200,
analyze_data:[
{
date:20-01-1920,
res:[
{
user_id:2,
store_id:5,
......
},
{
user_id:6,
store_id:8,
......
},
(nth num)
]
},
{
date:21-01-1999,
res:[
{
user_id:644,
store_id:66689,
......
},
{
user_id:6455,
store_id:877777,
......
},
(nth num)
]
},
...............,
...............,
...............,
(nth num)
],
graph_data:[
{
date:20-01-1920,
res:[
{
user_id:2,
store_id:5,
graph_details:{
x_axis: [1,2,3,4,5,8,955,44,55,141],
y_axis: [545,4545,77,55,88,228,822,5,22]
}
......
},
{
user_id:6,
store_id:8,
graph_details:{
x_axis: [154,2546,345,4456,5456,8456,955],
y_axis: [545,4545,77,55,88,228,822,5,22]
}
......
},
(nth num)
]
},
{
date:21-01-1999,
res:[
{
user_id:644,
store_id:66689,
graph_details:{
x_axis: [1,2,3,4,5,8,955,44,55,141],
y_axis: [545,4545,77,55,88,228,822,5,22]
}
......
},
{
user_id:6455,
store_id:877777,
graph_details:{
x_axis: [1,2,3,4,5,8,955,44,55,141],
y_axis: [545,4545,77,55,88,228,822,5,22]
}
......
},
(nth num)
]
},
...............,
...............,
...............,
(nth num)
]
}没有限制的文件。
重要的如何使用mongodb-PHP在一个连接中使用聚合和映射约简,并在一个实例中处理多个集合。
分享任何宝贵的资源/职位,在那里我得到了许可。
这是存储相关数据的正确方式吗?
请向我提供任何宝贵的资源。
谢谢。
发布于 2015-01-30 10:22:49
一个16 MB的MongoDB文档有一个大小限制。您可以使用GridFS来超过这个限制,但是在内部,您的文档在查找时被分割成16 MB块。因此,您的查询需要花费很长的时间。
我认为最好为文档中的每个数组创建一个集合,并将question_id和_id添加为id_ref (因为_id是一个保留键,所有值都必须是唯一的),这样就可以识别该数组元素。
Collection: analyze_data
{
id_ref:100,
question_id:200,
date:20-01-1920,
store_id:50,
user_id:6,
},
...
{
id_ref:100,
question_id:200,
date:20-01-2015,
store_id:6000,
user_id:600000,
},
etc. with other `id_ref`and `question_id`.graph_data的模拟集合。
您可以使用聚合框架通过date、store_id、user_id过滤两个集合,并通过匹配的ref_id或question_id将两个集合的结果组合回一个文档。
https://stackoverflow.com/questions/28230416
复制相似问题