简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM