【问题标题】:MongoDB with Parse Server index suggestion带有 Parse Server 索引建议的 MongoDB
【发布时间】:2020-07-23 01:28:15
【问题描述】:

我正在使用带有 Parse Server 的 mongoDB,并且即使我有索引也遇到了 COLLSCAN。 我正在访问 _Session 表并找到正确的“_session_token”。 js代码:

  let query = new Parse.Query('_Session');
  query.equalTo('sessionToken', userAuthToken);
  query.include('user');
  var session = await query.first({ useMasterKey: true });

索引:db.Session.createIndex( {"_session_token": 1} );

DocumentDB 分析结果:

 {
    "op": "query",
    "ts": 1595363106950,
    "ns": "production._Session",
    "command": {
        "find": "_Session",
        "filter": {
            "_session_token": "r:03c7703fcb856a97e475d1a306ea4f3b"
        },
        "sort": {},
        "projection": {},
        "limit": 1,
        "returnKey": false,
        "showRecordId": false,
        "$db": "production",
        "$readPreference": {
            "mode": "secondaryPreferred"
        }
    },
    "cursorExhausted": true,
    "nreturned": 1,
    "responseLength": 307,
    "protocol": "op_query",
    "millis": 952,
    "planSummary": "COLLSCAN",
    "execStats": {
        "stage": "SUBSCAN",
        "nReturned": "1",
        "executionTimeMillisEstimate": "902.042",
        "inputStage": {
            "stage": "LIMIT_SKIP",
            "nReturned": "1",
            "executionTimeMillisEstimate": "902.029",
            "inputStage": {
                "stage": "COLLSCAN",
                "nReturned": "1",
                "executionTimeMillisEstimate": "902.026"
            }
        }
    },
    "client": "",
    "user": ""
}

我该怎么办?如果我执行 db.Session.find({_session_token: "xpto"}) 会使用索引,但如果我使用 Parse,就会发生这种情况。

【问题讨论】:

    标签: mongodb parse-server


    【解决方案1】:

    使用以下方法创建索引:

    db.getCollection('_Session').createIndex( {"_session_token": 1} );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-03-23
      • 1970-01-01
      • 2014-02-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-12
      • 1970-01-01
      相关资源
      最近更新 更多