java - 关于mongodb 修改内嵌数据的修改问题
PHP中文网
PHP中文网 2017-04-17 17:39:11
0
1
278
{
    "_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中文网

认证高级PHP讲师

reply all(1)
阿神

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!