1

I am using Doctrine ODM(MongoDB). I am trying to write doctrine odm query builder to get the data where IDs IN (1,2,3). But i am not able to get it. Please help me on this.

I want to create odm query builder for the normal sql query like below,

SELECT * FROM USER WHERE id IN (1,2,3)

I hope there is no default function like findByID()

arrowd
  • 33,231
  • 8
  • 79
  • 110
Vinoth Babu
  • 6,724
  • 10
  • 36
  • 55
  • I don't know much about PHP/Doctrine, but the query you are looking for is `db.collection.find({ "id" : { "$in" : [1, 2, 3] } })`. This is similar to [this old SO question about Doctrine](http://stackoverflow.com/questions/21018417/doctrine-mongodb-find-by-id), so you may find it useful to help you write the query. – wdberkeley Feb 10 '15 at 19:54

1 Answers1

1

From the reference :

 $queryBuilder = $dm->createQueryBuilder('User')->field('id')->in([$id1,$id2,$id3]);
 $usersCollection = $queryBuilder->getQuery()->execute();

or for a single document:

$user = $dm->getRepository('User')->find($id);
diodoe
  • 46
  • 3