1

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.

Jimil Choksi
  • 351
  • 4
  • 9
  • What is the executed query, what is the result of that query when ran directly in mongo's console? The way you have so many arrays in your conditions is not normal, they are ~all unnecessary. It's not clear whether you and your colleague are talking to the same db; what your code is doing, and the problem isn't clear. – AD7six Jul 01 '15 at 09:58

1 Answers1

0

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')))
    )
);
Kotomono
  • 78
  • 1
  • 10