我要添加新的数据我嵌套数组
我的文档是:
{
"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 –