doctrine / DoctrineMongoDBBundle

Integrates Doctrine MongoDB ODM with Symfony
http://symfony.com/doc/current/bundles/DoctrineMongoDBBundle/index.html
MIT License
379 stars 229 forks source link

Doctrine ODM query for $lookup with let/pipeline #743

Closed azamalvi closed 1 year ago

azamalvi commented 2 years ago

I have a query that is working fine in mongo shell but I want to convert that query into ODM style but I did not find the conditional statement syntex. Below is my query

db.getCollection('Source').aggregate([{
 $lookup: {
  from: 'translated',
  localField: 'id',
  foreignField: 'sourceId',
  pipeline: [
   {
    $match: {
     tl: 'en'
    }
   }
  ],
  as: 'result'
 }
}, {}]

and I tried this but unable to add the piplelne

$this->createAggregationBuilder(Source::class)         
->lookup(Translated::class)
->localField('id')
->foreignField('sourceId')
// pipele should be here
->alias('result')
->getAggregation()->getIterator()->toArray();

What will be the right syntax/code to add pipleline/let with $lookup. Second question is that is there any way that we can run first Query directly without ODM style.

malarzm commented 1 year ago

The feature is missing but will be provided by https://github.com/doctrine/mongodb-odm/pull/2459