Sunday, March 13, 2022

[FIXED] Mongodb and Cakephp $all not searching for more than 1 record

Issue

I wanted to find all documents with the id of "1" and "2".

I have this code:

$user = $this->User->find('all', array('conditions' => array('_id' => array('$all' => array('1', '2')))));

When I try to debug $user, it doesn't show anything, But when I try to search for only 1 record like this:

$user = $this->User->find('all', array('conditions' => array('_id' => array('$all' => array('1')))));

it works.

I don't know why its not searching for 2 records.


Solution

I the end, I was able to figure out that I should use "$in" rather than "$all"



Answered By - comebal

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.