无法对时间序列集合执行非多重更新

Cannot perform a non-multi update on a time-series collection

您好,我正在使用新的 Timeseries mongodb 集合。我的 mongodb 版本是 5.0.6。我正在关注 this 教程。我创建了一个这样的集合。

   db.createCollection("ticker", {
     timeseries: {
        timeField: "time",
        metaField: "metadata",
    },
});

我是这样插入示例文档的。

db.ticker.insertOne({
 time: ISODate("20210101T01:00:00"),
 symbol: "BTC-USD",
 price: 34114.1145,
 metadata: { a: ""}
});

当我尝试更新元数据字段时出现上述错误。如前所述,here 是您只能更新 metaField 的限制,但它仍然给出上述错误。这是更新代码

db.ticker.update({ "metadata.a": "a" }, { $set: { "metadata.d": "a" } })

write failed with error: {
    "nMatched" : 0,
    "nUpserted" : 0,
    "nModified" : 0,
    "writeError" : {
        "code" : 72,
        "errmsg" : "Cannot perform a non-multi update on a time-series collection"
    }
}

我做错了什么需要帮助。

尝试添加 { multi: true } 配置。

如果您勾选 the docs,更新 time-series 集合仍然存在一些限制。

Update commands must meet the following requirements:

  • The query may only match on metaField field values.
  • The update command may only modify the metaField field value.
  • The update must be performed with an update document that contains only update operator expressions.
  • The update command may not limit the number of documents to be updated. You must use an update command with multi: true or the updateMany() method.
  • The update command may not set upsert: true.