search

Home  >  Q&A  >  body text

java - 关于mongodb 修改内嵌数据的修改问题

{
    "_id" : ObjectId("570b500b517682cebe1183ee"),
    "userName" : "m27",
    "colonizeStations" : [
        {
            "uid" : 1,
            "sid" : 703,
            "name" : "colonizeship_name",
            "state" : 1,
            "starId" : 0,
            "refineBuildingMap" : [
                {
                    "sid" : 2002,
                    "x" : -4.7412109375,
                    "y" : 2.248198986053467,
                    "z" : 4.6328125,
                    "lastCollectResourceTime" : 1460367845,
                    "lastCollectionAdditionTime" : 1460367845,
                    "resource" : 0
                },
                {
                    "sid" : 2052,
                    "x" : -4.60888671875,
                    "y" : 4.834808349609375,
                    "z" : 2.093750476837158,
                    "lastCollectResourceTime" : 1460367857,
                    "lastCollectionAdditionTime" : 1460367857,
                    "resource" : 0
                }
            ]
        }
    ]
}

我想修改 最里面的文档的 “lastCollectionAdditionTime”和”resource”这两个值… 怎么写.
因为不想动到其他的字段.. 我只会修改一层内嵌的数据, 这个是在第二层..
求教大神...

PHP中文网PHP中文网2810 days ago318

reply all(1)I'll reply

  • 阿神

    阿神2017-04-17 17:41:11

    This is not a question of how many layers, but that there are arrays in the object

    "$set": {
        "colonizeStations.0.refineBuildingMap.<N>.lastCollectionAdditionTime": <NEW VALUE>
    }

    <N>Indicates which element in the array

    reply
    0
  • Cancelreply