D
D
dezconnect2011-11-18 19:06:32
PHP
dezconnect, 2011-11-18 19:06:32

[SOLVED] MongoDB PHP and magic $OR

The following question arose ...

How to make a request from PHP to mongo with $OR

In mongo:

{ empl_type: { $in: [ 'programmers', 'admins' ] }, $or: [{ p_phone : true }, { a_phone: false}] }


In php: swears: Uncaught exception 'MongoCursorException' with message '$or requires nonempty array' Maybe someone has already encountered and knows how to solve this issue?
$categories = array('programmers', 'admins');

$filters = array(
array('p_phone' => 'true'),
array('a_phone' => 'false'),
);


$data = $empls->find(array('empl_type' => array('$in' => $categories), '$or' => $filters));



Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sajgak, 2011-11-18
@sajgak

pulled from a live project

$this->library('mongo')->find('guide', array('$or' => array(array('edited_uid' => $uid), array('created_uid' => $uid))));

D
dezconnect, 2011-11-18
@dezconnect

Thanks for the answer =) But it didn't help. It turned out that true and false should be written as is, and not as a string.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question