Jimil Choksi
Jimil Choksi

Reputation: 350

No result for mongodb query

I am using ichikaway mongodb plugin for cakephp. cakephp version is 2.5.1
ichikaway mongodb shell version 2.6.8.

I use following simple find first code:

$conditions['$and'] = array(
    array('User.username' => $this->Cookie->read('username')),
    array('User.status' => 'active'),
    array('User.password' => 
       AuthComponent :: password($this->Cookie->read('password'))
    )
);

$adminData=$this->User->find('first',array('conditions'=> $conditions));

but it returns Null.

The same code I run in my colleagues' computer which works. I debug the code and got the query which I fire in Mongo Shell and RoboMongo which works and shows result.
Also

$this->User->read()

is also not working.

Query generated in log as follows.

Query : db.companies.find( {"status":{"$in":["active","create"]}}, ["id","company_name"] ).sort( [] ).limit( 0 ).skip( 0 ).hint( [] ) Time : 0

Query : db.companies.find( {"_id":ObjectId ("557be027c01afed1068b4567")}, [] ).sort( [] ).limit( 1 ).skip( 0 ).hint( [] ) Time : 0

above query in Robomongo and mongo Terminal returns one result.
But in cakephp this query doesn't return result.

Upvotes: 1

Views: 345

Answers (1)

Kotomono
Kotomono

Reputation: 78

just try this code, it's work for me

$conditions = array(
    '$and' => array(
        array('User.username' => $this->Cookie->read('username')),
        array('User.status' => 'active'),
        array('User.password' => AuthComponent :: password($this->Cookie->read('password')))
    )
);

Upvotes: 0

Related Questions