[英]How to find a sub array in cakephp with mongodb
I have this problem with mongodb using cakephp. 我在使用Cakephp的mongodb遇到此问题。 I don't know how to find a record with its sub-array.
我不知道如何用其子数组查找记录。
I have this structure in mongodb 我在mongodb中有这个结构
id:"xxx",
profile:[
{
profile_pic:"xxx",
firstname:"xxx",
lastname:"xxx",
slug:"xxx"
}
] ]
I pass on the slug variable in the controller and I want to get the corresponding record with its slug. 我在控制器中传递slug变量,并希望获得带有该slug的相应记录。 I use this code:
我使用以下代码:
$profile = $this->User->find('first', array('first', array('conditions' => array('User.profile.slug' => $this->request['slug']))));
But this code is not working. 但是此代码不起作用。
Aiyoh, 爱瑜
I had the wrong query in my profile. 我的个人资料中的查询错误。 Should be:
应该:
$profile = $this->User->find('first', array('conditions' => array('profile.slug' => $this->request['slug'])));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.