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

标签 mongodb mongodb-query time-series

您好,我正在使用新的 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 , 更新时间序列集合仍然存在一些限制。

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.

关于mongodb - 无法对时间序列集合执行非多重更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71093789/

相关文章:

java - Spring Data相当于聚合查询

mongodb - 使用mgo在MongoDB中进行有效的分页

time-series - 动态时间扭曲和 Needleman-Wunsch 算法有什么区别?

node.js - 在 Mongoose 中合并两个文档的数组

python - 带有 ssl 证书的 flask mongoengine

javascript - 使用其他字段的数据创建 ID

python - 喀拉斯 LSTM : a time-series multi-step multi-features forecasting - poor results

python - 使用 Pandas 自相关图 - 如何限制 x 轴以使其更具可读性?

python - json_utils.dumps 突然从 flask 中返回所有 unicode

mongodb - Pubspec.yaml引发不一致的错误并且没有冲突