如何更新嵌套文档中的多个值?

时间:2019-07-10 19:32:26

标签: mongodb mongodb-query

我对MongoDB完全陌生。我有个人资料文档,每个个人资料都包含语言文档。

{ 
    "_id" : ObjectId("5d23134bbd43c3208034f86f"), 
    "name" : "name1", 
    "languages" : 
        [ 
            { 
                "_id" : ObjectId("5d26321e920fba2c147dec73"), 
                "language" : "English", 
                "proficiency" : "elem" 
            }, 
            { 
                "_id" : ObjectId("5d2632a5920fba2c147dec74"), 
                "language" : "Italian", 
                "proficiency" : "prof" 
            }
        ], 
    "status" : "ACTIVE"
},
{ 
    "_id" : ObjectId("5d231352bd43c3208034f870"), 
    "name" : "name2", 
    "languages" : 
        [ 
            { 
                "_id" : ObjectId("5d26321e920fba2c147dec75"), 
                "language" : "Russian", 
                "proficiency" : "elem" 
            }, 
            { 
                "_id" : ObjectId("5d2632a5920fba2c147dec76"), 
                "language" : "Ukranian", 
                "proficiency" : "inter" 
            }
        ], 
    "status" : "ARCHIVED"
} 

我想更新个人档案文档中的所有熟练程度(元素->基本,中间->中间,教授->熟练)。有帮助吗?

1 个答案:

答案 0 :(得分:2)

您需要$ positional filtered operator

String line;
while((line=br.readLine())!=null){
    <process one line>
}