Home > Blockchain >  Cannot perform a non-multi update on a time-series collection
Cannot perform a non-multi update on a time-series collection

Time:02-14

Hi I am using newly Timeseries mongodb collection. My mongodb version is 5.0.6. I am following this tutorial. I create a collection like this.

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

I inserted the sample document like this.

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

When I am trying to update metadata field it gives above error. As mentioned here is limitation you can only update metaField but still it is giving above error. Here is the update code

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"
    }
}

Need help what I am doing wrong.

CodePudding user response:

Try adding { multi: true } config.

If you check the docs, there are still some limitations for updating time-series collections.

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.
  • Related