Dear all,
mongo 5.0.4 shard cluster, how to update shard key.
I am searching in google several days, i still do not get the answer.
first> i try to use : db.table01.updateOne({id:1},{$set:{id:8888}}) (id is my hashed shard key)
i get the error:Must run update to shard key field in a multi-statement transaction or with retryWrites: true."
then> try :db.table01.update({id:1},{$set:{id:8888}},{multi:true})
get the error:Multi-update operations are not allowed when updating the shard key field
then>I login mongos using mongo --retrywrites true, try : db.table01.updateOne({id:1},{$set:{id:8888}})
i get the error:Update operation was converted into a distributed transaction because the document being updated would move shards and that transaction failed. :: caused by :: Transaction was aborted :: caused by :: from shard rs_shard03 :: caused by :: ‘prepareTransaction’ is not supported for replica sets with arbiters"
i read the document , update shard key should in a transaction or retrywrites:true.
it seems that login mongs using --retrywrites true does not work.
so i try to use a transaction:
var session = db.getMongo().startSession()
session.startTransaction()
var tb1 = session.getDatabase(‘testdb01’).getCollection(‘table01’)
tb1.updateOne({id:1},{$set:{“id”:“88888”}},{multi:false})
session.commitTransaction()
i get the same error:
‘prepareTransaction’ is not supported for replica sets with arbiters",
I can see you have solved your issue in the following post
Please note, as per the documentation, that transactions whose write operations span multiple shards will error and abort if any transaction operation reads from or writes to a shard that contains an arbiter.
As the error message “‘prepareTransaction’ is not supported for replica sets with arbiters” indicates, you need to replace the arbiter with a data-bearing secondary in order to use transactions or modify shard keys (which uses transactions).