douling8772 2010-12-03 19:38
浏览 44
已采纳

MongoDB PHP嵌套文档

ok lets say i have this collection in my tv database

"season" : "1", "episodes" : {"code" : ["1x01", "1x02", "1x03"], "title" : ["Dont Look Back", "Genesis", "Third"]},
"season" : "2", "episodes" : {"code" : ["2x01", "2x02", "2x03"], "title" : ["D2ont Look Back", "G2enesis", "T2hird"]},
"season" : "3", "episodes" : {"code" : ["3x01", "3x02", "3x03"], "title" : ["D3ont Look Back", "G3enesis", "T3hird"]},
"season" : "4", "episodes" : {"code" : ["4x01", "4x02", "4x03"], "title" : ["D4ont Look Back", "G4enesis", "T4hird"]}

how do i make it so that only, lets say the episodes from season 2 are shown? ive been trying using
echo $obj['episodes']['code'][0];
but it only shows episodes from the last row

im pretty sure my nesting is all wrong but im new to mongo and im having trouble trying to map this out

any advice?

  • 写回答

1条回答

  • douzhai7873 2010-12-03 21:09
    关注

    You need to use find() first. $a = $coll->findOne(array('season' => '2'); That will return an array $a which will have keys 'episodes', 'title' So once you find the document with findOne, you would then just access the data using $a['title'] or whatever fields you need

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥50 汇编语言除法溢出问题
  • ¥65 C++实现删除N个数据列表共有的元素
  • ¥15 Visual Studio问题
  • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波