我要添加新的數據我嵌套數組
我的文檔是:
{
"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'
))
)
);
只是爲了填補你在這裏downvote或投票結束的原因。在您的問題中發佈相關的代碼部分。不要在外部鏈接(可能會中斷),也不要讓我們閱讀儘管長列表只是爲了弄清楚你在說什麼。閱讀此:http://stackoverflow.com/help/mcve –