On this page本页内容
If you have missing shard key fields, you can set the shard key field to 如果缺少分片键字段,可以将分片键字段设置为null
. null
。If you want to set the missing shard key field to a non-如果要将缺少的分片键字段设置为非null
value, see Change a Document's Shard Key Value.null
值,请参阅更改文档的分片键值。
To perform the update, you can use the following operations on a 要执行更新,可以在mongos
:mongos
上使用以下操作:
multi: true multi: true 更新 | db.collection.updateMany() |
|
multi: false multi: false 更新 |
| |
findAndModify |
|
|
|
Consider a 考虑在sales
collection which is sharded on the location
field. location
字段上分片的sales
集合。Some documents in the collection have no 集合中的某些文档没有location
field. location
字段。A missing field is considered the same as a null value for the field. 缺少的字段被视为与该字段的空值相同。To explicitly set these fields to 要将这些字段显式设置为null
, run the following command:null
,请运行以下命令:
db.sales.updateOne( { _id: 12345, location: null }, { $set: { location: null } } )
When setting missing shard key fields with 使用db.collection.updateOne()
or another method that explicitly updates only one document, the update must meet one of the following requirements:db.collection.updateOne()
或其他只显式更新一个文档的方法设置缺少的shard键字段时,更新必须满足以下要求之一:
_id
_id
完全匹配的项