Reputation: 340
My project is using Laravel and jenssegers/laravel-mongodb ext. I have a query with lookup:
'$lookup' => [
'from' => 'proposals',
'localField' => '_id',
'foreignField' => 'proposal_round_mongo_id',
'as' => 'proposal'
]
Proposal has a property status
. How can I "join" propsoals with select data with where status="active"
condition?
Upvotes: 0
Views: 693
Reputation: 3240
You can use the pipeline option to achieve this. However you will need to read the document of the extension which is you used. But as mongoshell you can do as follow
{
$lookup:
{
from: <collection to join>,
let: { <var_1>: <expression>, …, <var_n>: <expression> },
pipeline: [ <pipeline to execute on the collection to join> ],
as: <output array field>
}
}
And specify condition inside pipeline. Read from the following link. https://docs.mongodb.com/manual/reference/operator/aggregation/lookup/#join-conditions-and-uncorrelated-sub-queries
Upvotes: 1