MongoDB - Update or Insert object in array

后端 未结 7 1959
醉话见心
醉话见心 2020-12-08 04:26

I have the following collection

{
    "_id" : ObjectId("57315ba4846dd82425ca2408"),
    "myarray" : [ 
        {
            use         


        
7条回答
  •  遥遥无期
    2020-12-08 05:17

    array update and create don't mix in under one query, if you care much about atomicity then there's this solution:

    normalise your schema to,

    {
        "_id" : ObjectId("57315ba4846dd82425ca2408"),
        userId : ObjectId("570ca5e48dbe673802c2d035"),
        point : 5
    }
    

提交回复
热议问题