带有mongoDB WHERE条件的Cakephp无法正常工作 [英] Cakephp with mongoDB WHERE condtion not worked

查看:45
本文介绍了带有mongoDB WHERE条件的Cakephp无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在新的mongoDB中使用cakephp。

I am newer in mongoDB with cakephp.

CakePHP代码

$adminData=$this->Admin->find('first',array('conditions'=>array(
                    'OR'=>array('Admin.username'=>$this->data['Admin']['username'],'Admin.email'=>$this->data['Admin']['username']),
                    'AND'=>array('Admin.password'=>AuthComponent::password($this->data['Admin']['password'])))));

等效的 mongoDB查询

db.admins.find( {"OR":{"username":"admin","email":"admin"},
                 "AND":{"password":"b3dfaf29547a69faaaaf63e1223bb4c479c80203"}},
                [] ).sort( [] ).limit( 1 ).skip( 0 ).hint( [] ) 

我的问题是cakephp生成自动mongoDB查询,但它不起作用。所以我的问题是:

My problem is cakephp generate automatic mongoDB query but it not working. SO my question is :


我必须为此设置任何配置或安装任何插件,或者我必须为此编写代码。如果需要更多信息,我会给出。

I have to set any configuration for it or install any plugin for that Or I have to written code for that. If more information required I will give.


推荐答案

Cake PHP似乎直接将查询转置为MongoDB自己的查询文档,因为这样的查询是完全错误的,您应该尝试:

It seems Cake PHP directly transposes the query into MongoDBs own query document as such your query is completely wrong, you should try:

$adminData = $this->Admin->find(
    'first',
     array('conditions' => array(
         '$or' => array(
             array('Admin.username' => $this->data['Admin']['username']), 
             array('Admin.email' => $this->data['Admin']['username'])
         ),
         'Admin.password'=>AuthComponent::password($this->data['Admin']['password'])
     ))
);

类似的东西。

这篇关于带有mongoDB WHERE条件的Cakephp无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆