亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

嵌套數組中的MongoDB$Push

嵌套數組中的MongoDB$Push

隔江千里 2019-06-19 14:41:09
嵌套數組中的MongoDB$Push我想要添加新的數據,我的嵌套數組我的文件是:{   "username": "erkin",   "email": "[email protected]",   "password": "b",   "playlists": [     {       "_id": 58,       "name": "asdsa",       "date": "09-01-15",       "musics": [         {           "name": "INNA - Cola Song (feat. J Balvin)",           "duration": "3.00"         },         {           "name": "blabla",           "duration": "3.00"         }       ]     }   ]}我想在這個播放列表中添加音樂:{   "username": "erkin",   "email": "[email protected]",   "password": "b",   "playlists": [     {       "_id": 58,       "name": "asdsa",       "date": "09-01-15",       "musics": [         {           "name": "INNA - Cola Song (feat. J Balvin)",           "duration": "3.00"         },         {           "name": "blabla",           "duration": "3.00"         },         {           "name": "new",           "duration": "3.00"         }       ]     }   ]}以下是我嘗試過的:$users->update(   array(     '_id' => new MongoId (Session::get('id')),     'playlists._id' => $playlistId  ),   array(     '$push' => array('playlists.musics' => array(       'name' => 'newrecord',       'duration' => '3.00'     ))   ));
查看完整描述

2 回答

?
慕桂英546537

TA貢獻1848條經驗 獲得超10個贊

可能是這樣的,ID是你的對象。第一個{}是標識文檔所必需的。只要集合中有另一個唯一標識符,就不需要使用objectid。

db.collection.update(
    { "_id": ID, "playlists._id": "58"},
    { "$push": 
        {"playlists.$.musics": 
            {
                "name": "test name",
                "duration": "4.00"
            }
        }
    })


查看完整回答
反對 回復 2019-06-19
  • 2 回答
  • 0 關注
  • 1032 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號