您好,我正在使用新的 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/