0

I'm having a problem using a dynamic array to filter the data I want to retrieve from my MongoDB.

I have an array which is stored in $this->x and when I print_r($this->x) the result is the same as before:

Array
(
    [0] => 1
    [1] => 2
    [2] => 54
    [3] => 55
)

but the query won't return any values. Query -> $c = $col->find(array('Aliens.Id' => array('$in' => $this->x)));

The strange thing is that when I do the query like this -> $c = $col->find(array('Aliens.Id' => array('$in' => array(1,2,54,55))); it returns values!!

If I print_r(array(1,2,54,55)) the output is:

Array
(
    [0] => 1
    [1] => 2
    [2] => 54
    [3] => 55
)

Note: $this->x is also an array.

3
  • 1
    check this one stackoverflow.com/questions/9950525/… Commented Jan 23, 2018 at 12:12
  • Thansk a lot @prakashtank. It was built as an array of strings Commented Jan 23, 2018 at 12:28
  • glad it worked !!! Commented Jan 23, 2018 at 12:48

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.