2

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?

2
  • myvar is a tag and B00LHILHS8 is a value?? Commented Feb 16, 2016 at 13:48
  • @Cuchu - Yes. I have a document with severals field and myvar is one of them. Commented Feb 16, 2016 at 13:49

1 Answer 1

2

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

try:

$qb = $dm->createQueryBuilder('Entity')
    ->field('myvar')->in(array('B00LHILHS8', 'B00WSCCMV8'));
Sign up to request clarification or add additional context in comments.

5 Comments

I use doctrine but with mysql and mongodb with php api.
and then $query = $qb->getQuery(); $result = $query->execute();
Thanks, working with the QueryBuilder helped me - but the problem is, that findBy() seems not work with Doctrine and MongoDB properly. With mysql it does.
findBy use array(field1 => value1, field2 => value2)
@Roman MongoDB will happily hold array value in the document so effectively your query is asking for myvar with an array as its value - this is perfectly valid in MongoDB world :)

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.