即使我通过 RESTHeart 5.1.5 执行 POST 来添加文档,为什么 Mongo DB 仍检查 _etag?

问题描述 投票:0回答:1

使用 RESTHeart 5.1.5,我尝试通过 HTTP POST 将文档添加到集合 myapp 中。

POST http://xyz:9998/logs/myapp?checkETag=false
{
  "diff": {
    "address": {
      "addressLine2": [
        "152 Broadway, Suite 600",
        "150 Broadway, Suite 600"
      ]
    }
  },
  "tracking": {
    "resourceId": "2f9af48b-2a7c-47ce-bccc-0b29c1188648",
    "login": "MYDOMAIN\user1",
    "timestamp": "2024-04-08T15:01:28.671Z"
  }
}

我注意到性能一点都不好,并且 Mongo DB 通过 findAndModify 系统地扫描集合中的所有文档(即使我正在执行 POST)。

{
  "t": {
    "$date": "2024-04-08T17:01:28.731+02:00"
  },
  "s": "I",
  "c": "COMMAND",
  "id": 51803,
  "ctx": "conn29",
  "msg": "Slow query",
  "attr": {
    "type": "command",
    "ns": "logs.myapp",
    "command": {
      "findAndModify": "myapp",
      "query": {
        "_etag": {
          "$oid": "661406338bd44174052a37a9"
        }
      },
      "new": true,
      "upsert": true,
      "update": {
        "diff": {
          "address": {
            "addressLine2": [
              "152 Broadway, Suite 600",
              "150 Broadway, Suite 600"
            ]
          }
        },
        "tracking": {
          "resourceId": "2f9af48b-2a7c-47ce-bccc-0b29c1188648",
          "login": "MYDOMAIN\\user1",
          "timestamp": "2024-04-08T15:01:28.671Z"
        },
        "_etag": {
          "$oid": "661406c88bd44174052a37aa"
        }
      },
      "$db": "logs"
    },
    "planSummary": "COLLSCAN",
    "keysExamined": 0,
    "docsExamined": 2766646,
    "nMatched": 0,
    "nModified": 0,
    "upsert": true,
    "keysInserted": 2,
    "numYields": 2766,
    "queryHash": "EE3A823E",
    "planCacheKey": "EE3A823E",
    "reslen": 611,
    "locks": {
      "ParallelBatchWriterMode": {
        "acquireCount": {
          "r": 2767
        }
      },
      "FeatureCompatibilityVersion": {
        "acquireCount": {
          "w": 2767
        }
      },
      "ReplicationStateTransition": {
        "acquireCount": {
          "w": 2767
        }
      },
      "Global": {
        "acquireCount": {
          "w": 2767
        }
      },
      "Database": {
        "acquireCount": {
          "w": 2767
        }
      },
      "Collection": {
        "acquireCount": {
          "w": 2767
        }
      },
      "Mutex": {
        "acquireCount": {
          "r": 1
        }
      }
    },
    "flowControl": {
      "acquireCount": 2767,
      "timeAcquiringMicros": 1030
    },
    "storage": {
      "data": {
        "bytesRead": 101067941,
        "timeReadingMicros": 96970
      }
    },
    "protocol": "op_msg",
    "durationMillis": 1593
  }
}

我尝试在 URL 中添加参数 checkETag=false 但没有效果。

mongodb restheart
1个回答
0
投票

RESTHeart v5 过去总是使用

findOneAndReplace

以 upsert 语义编写文档

从 RESTHeart v6(最新版本是 v7.7.7)开始,写入操作取决于写入模式,即

?wm
查询参数。 POST 的默认写入操作是
insertOne

如果写入完成并检查

_etag
,则必须在该字段上创建索引(如果集合是由 RESTHeart 创建的,则会自动创建,否则必须由您创建)。

参见 https://restheart.org/docs/mongodb-rest/write-docs#mongodb-write-operations

© www.soinside.com 2019 - 2024. All rights reserved.