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

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

报告相同问题?

悬赏问题

  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元