我们可以在一个文档中存储数十万个数据,而mongoDb没有任何性能问题吗?

时间:2015-01-30 06:31:54

标签: mongodb mongodb-php

我是mongodb的新手。 需要了解使用> 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)
    ]

}

我在我的收藏中有这种类型的文档,我必须根据日期,store_id,user_id analyze_data graph_data >

过滤后我需要进行一些计算并重组我的数组。

{
    _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 在一个连接中使用聚合和地图缩减,并在一个实例中使用多个集合。

分享我被清除的任何有价值的追索权/邮寄。

这是存储相关数据的正确方法吗?

  1. 这是在mongo中存储数据的正确方法吗?
  2. 是否会出现性能问题?
  3. 减少和重组输出的最佳方法是什么? 给我?
  4. 请提供任何宝贵的资源..

    谢谢。

1 个答案:

答案 0 :(得分:1)

一个MongoDB Document has a size limit的16 MB。您可以使用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的模拟集合。

您可以使用aggregation frameworkdatestore_iduser_id过滤这两个集合,并通过匹配{将两个集合的结果合并回一个文档{1}}或ref_id