嵌套数组中的MongoDB$Push我想要添加新的数据,我的嵌套数组我的文件是:{
"username": "erkin",
"email": "erkin-07@hotmail.com",
"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": "erkin-07@hotmail.com",
"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个赞
db.collection.update( { "_id": ID, "playlists._id": "58"}, { "$push": {"playlists.$.musics": { "name": "test name", "duration": "4.00" } } })
- 2 回答
- 0 关注
- 1001 浏览
添加回答
举报
0/150
提交
取消