【问题标题】:Mongodb query hanging systemMongoDB查询挂机系统
【发布时间】:2017-01-16 07:25:40
【问题描述】:

我使用的是 MongoDB 2.6 版。

我有大约 300 万条数据。 当我触发以下查询时,它会挂起我的整个 Java 应用程序。

(我正在使用Mongodb connector 从那里检索数据。)

db.collection_name.find{
    "client_id.event.currentDate": {
        $gte: "2016-12-18",
        $lte: "2017-01-17"
    },
     "client_id.event.name": "SEARCH HOTELS SUCCESS",
    _id: {
        $lt: ObjectId('5856428ce4b0f530cc74c090')
    }
}

检索此类大数据的最佳方法是什么?

编辑 1:

我的收藏有一个索引

{"client_id.event.name" : 1 ,"_id" :1 ,"client_id.event.currentDate" :1} 

编辑 2:

来自数据库的示例文档:

{
        "_id" : ObjectId("57a316a60cf26576defb7837"),
        "client_id" : {
                "clientIp" : "50.23.117.45",
                "event" : {
                        "installationId" : "us2zv39vti5v",
                        "action" : "END",
                        "client_us_lastCommunicatedAt" : "2016-08-01T10:23:38.502Z",
                        "duration" : 60,
                        "client_us_userUpdatedOn" : null,
                        "name" : "APPSESSION",
                        "appId" : 3,
                        "userName" : "us2zv39vti5v",
                        "currentDate" : "2016-08-01T10:24:38.502Z",
                        "superProperties" : {
                                "client_us_installAt" : "2016-08-01T10:23:38.502Z",
                                "client_us_cookieEnabled" : true,
                                "client_us_referrer" : "Self",
                                "client_us_screen_width" : 768,
                                "client_us_counter" : 1,
                                "client_us_screen_height" : 1360,
                                "client_us_brand" : "Google",
                                "client_us_browser_version" : "23.32.12.20",
                                "client_us_screen_dpi" : 96,
                                "client_us_os" : "Windows",
                                "client_us_screen_colourDepth" : 24,
                                "client_us_os_version" : "10",
                                "client_us_flashVersion" : "no check",
                                "client_us_lastCommunicatedAt" : "2016-08-01T10:23:38.502Z",
                                "browser" : "Chrome",
                                "client_us_screen_pixelDepth" : 0,
                                "client_us_referring_domain" : "Self",
                                "client_us_css_pixel" : 1,
                                "client_us_mobile" : false
                        },
                        "userProperties" : {
                                "duration" : 60,
                                "Country" : "IN"
                        },
                        "installProperties" : {
                                "email" : "us2zv39vti5v@gmail.com"
                        }
                }
        }
}

【问题讨论】:

  • 不应该是引号中的嵌入字段名称,如"client_id.event.currentDate"?
  • 已编辑,请再看一遍。我在这里错过了有问题的双引号,但在真正的查询中它在那里。
  • 你需要调查什么挂了。通常,它是在您的 MongoDB 实例上运行的查询执行,而不是从 MongoDB 加载的数据。处理大型数据集最好使用流式处理。
  • 您能否更新您的问题以包含该集合中的几个文档,以便我们可以看到文档架构?这将专门回答关于字段"client_id.event.currentDate"的数据类型是什么的问题...
  • 能否请您再看一下这个问题。我已将我的数据库索引为问题中的更新

标签: java mongodb mongodb-query aggregation-framework spring-data-mongodb


【解决方案1】:

您有 300 万条数据,每个数据至少有 4 个 Date 字段。 现在,当 spring-mongo-data 从 mongo 请求所有这些时,它必须将 date 的 String 值(这是一种 json string date format = Java String )转换为 1200 万个日期的 java Date 对象。所以需要一段时间。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-15
    • 1970-01-01
    • 2021-11-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多