我有这个数据集
_id: 654e312d4ff391e4ef2244ad
Id: 2
SepalLengthCm: 4.9
:3
PetalLengthCm: 1.4
PetalWidthCm: 0.2
Species: "Iris-setosa"
而mongodb是这样识别的,
{
"Id": 2,
"SepalLengthCm": 4.9,
"PetalLengthCm": 1.4,
"PetalWidthCm": 0.2,
"Species": "Iris-setosa"
}
他忽略了“:3”,尽管保存了它们。
我尝试重命名,但不起作用,因为 mongo 无法识别“”。 像这样的东西:
db.collection.updateMany({}, { $rename: { "": "tmpName" } });
db.collection.updateMany({}, { $rename: { " ": "tmpName" } });
我需要在“:3”中放置一个标题
{
"Id": 2,
"SepalLengthCm": 4.9,
"tmpName":3,
"PetalLengthCm": 1.4,
"PetalWidthCm": 0.2,
"Species": "Iris-setosa"
}
使用
$getField
访问该字段并使用 $set
访问新的 tmpField
db.collection.update({},
[
{
"$set": {
"tmpField": {
"$getField": {
"field": "",
"input": "$$CURRENT"
}
}
}
}
])