@@ -1449,23 +1449,35 @@ export class FormsAngular {
1449
1449
case "$graphLookup" :
1450
1450
let needFindFunc = true ;
1451
1451
if ( keys [ 0 ] === "$lookup" ) {
1452
- // For now at least, we only support simple $lookups with a single join field equality
1453
1452
let lookupProps = Object . keys ( stage . $lookup ) ;
1453
+ // First deal with simple $lookups with a single join field equality
1454
1454
if (
1455
- lookupProps . length !== 4 ||
1456
- lookupProps . indexOf ( "from" ) === - 1 ||
1457
- lookupProps . indexOf ( "localField" ) === - 1 ||
1458
- lookupProps . indexOf ( "foreignField" ) === - 1 ||
1459
- lookupProps . indexOf ( "as" ) === - 1
1455
+ lookupProps . length === 4 &&
1456
+ lookupProps . includes ( "from" ) &&
1457
+ lookupProps . includes ( "localField" ) &&
1458
+ lookupProps . includes ( "foreignField" ) &&
1459
+ lookupProps . includes ( "as" )
1460
1460
) {
1461
+ // If we are doing a lookup using an _id (so not fishing) we don't need to do the findFunc (see tkt #12399)
1462
+ if ( stage . $lookup . foreignField === "_id" ) {
1463
+ needFindFunc = false ;
1464
+ }
1465
+ } else if (
1466
+ lookupProps . length === 4 &&
1467
+ lookupProps . includes ( "from" ) &&
1468
+ lookupProps . includes ( "let" ) &&
1469
+ lookupProps . includes ( "pipeline" ) &&
1470
+ lookupProps . includes ( "as" )
1471
+ ) {
1472
+ // can't think of a way to exploit this (if you add a findFunc) but it is the responsibility of the user
1473
+ // to ensure that the pipeline returns fields used by the findFunc
1474
+ console . log ( `In some scenarios $lookups that use pipelines may not provide all the fields used by the 'findFunc' of a collection.
1475
+ If you get no results returned this might be the explanation.` )
1476
+ } else {
1461
1477
throw new Error (
1462
- " No support for $lookup that isn't Equality Match with a Single Join Condition"
1478
+ ` No support for $lookup of with properties ${ lookupProps . join ( ', ' ) } `
1463
1479
) ;
1464
1480
}
1465
- // If we are doing a lookup using an _id (so not fishing) we don't need to do the findFunc (see tkt #12399)
1466
- if ( stage . $lookup . foreignField === "_id" ) {
1467
- needFindFunc = false ;
1468
- }
1469
1481
}
1470
1482
// hide any hiddenfields in the lookup collection
1471
1483
const collectionName = stage [ keys [ 0 ] ] . from ;
0 commit comments