Vinoth Babu
Vinoth Babu

Reputation: 6852

Doctrine-ODM (MongoDB) - FindByMultipleIDs

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()

Upvotes: 1

Views: 118

Answers (1)

diodoe
diodoe

Reputation: 46

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);

Upvotes: 1

Related Questions