Roman
Roman

Reputation: 2549

FindBy('myvar' => $array) not working with mongoDbOdm in Symfony3?

I have filled a mongodb-collection with the following values (identifer = myvar):

array (size=10)
  0 => string 'B00LHILHS8' (length=10)
  1 => string 'B00WSCCMV8' (length=10)
  2 => string 'B00MA15OK8' (length=10)

However - findBy(['myvar' => 'B00LHILHS8']) returns the document as wanted. But findBy(['myvar' => ['B00LHILHS8', 'B00WSCCMV8']]) returns an empty result.

I am not sure, if this is right. As the Doctrine Manual - Working with objects - By Simple Conditions mentions, that it should be possible to pass an array for the findBy() method.

Should i use the query-builder instead?

Upvotes: 2

Views: 108

Answers (1)

Maxi Schvindt
Maxi Schvindt

Reputation: 1462

use doctrine-mongodb-odm with Conditional Operators [link]

try:

$qb = $dm->createQueryBuilder('Entity')
    ->field('myvar')->in(array('B00LHILHS8', 'B00WSCCMV8'));

Upvotes: 2

Related Questions