我使用的是mongo 4.2版本。我已经创建了一个分片的集合。我想要更新几个字段的值,其中包括分片的键。根据mongo文档,https://docs.mongodb.com/manual/core/sharding-shard-key/#change-a-document-s-shard-key-value .It说我们可以更新分片键的值。但是我得到了以下错误
Performing an update on the path 'status' would modify the immutable field 'status'请告诉我这里遗漏了什么
我尝试了下面的查询
.updateOne({date:{'$gte': '2021-01-01', '$lte': '2021-01-15'},
status: 'U' ,
type: 'SC',
name: 'product1',
currency: 'INR' },
{$set: {status: 'M'}})这是分片密钥
shard key: {
"date" : 1,
"status" : 1,
"type" : 1,
"name" : 1,
"currency" : 1
}发布于 2021-04-20 22:08:02
首先,确保您没有在与以前版本的db.adminCommand( { setFeatureCompatibilityVersion: "4.2" } )兼容的功能模式下运行数据库。分片键在v4.2之前是不可变的。
然后确保没有文档的"status“是复合主键_id:.find( { "_id.status": {$exists: true} } )的一部分。不管如何分片,_id仍然是不可变的,这也是使用ObjectID作为主键的原因之一。
https://stackoverflow.com/questions/67173917
复制相似问题