我有这样的文件,
{
    "S" : {
        "500209" : {
            "total_income" : 38982,
            "interest_income" : 1714,
            "reported_eps" : 158.76,
            "year" : 201303
        }
    },
    "_id" : "pl"
}
我正在尝试像这样更新此文档,
{
    "S" : {
        "500209" : {
            "total_income" : 38982,
            "interest_income" : 1714,
            "reported_eps" : 158.76,
            "year" : 201303,
            "yield": 1001,  <== inserted a new attribute
        }
    },
    "_id" : "pl"
}
我试过这个,
db.my_collection.update({_id: 'pl'},{$set: {'S.500209.yield': 1}})
但我做不到。我在堆栈溢出和谷歌中搜索但我找不到。
我得到了很多答案,但其中大多数都将子文档保存在数组中。
请帮我解决我的问题,并请告诉我为什么他们中的大多数人都将子文档保存在数组中。