How to form the complex aggregation pipeline using MongoC driver API. I know BCON_NEW can be used to form the hard-coded pipeline but If we want to form pipeline run time. What are the various ways available? Can you provide some complex example.
E.g. If I want to build below aggregation pipeline:
db.t5.aggregate([ {$lookup: {
from: "t6",
let: {id_field: "$id", age_field: "$age", name_field: "$name"},
pipeline: [ { $match:{ $expr:{
$and: [
{ $or: [
{ $eq: [ "$old", "$$age_field" ] },
{ $eq: [ "$no", "$$id_field"] }
]}
,{ $eq: ["$alias", "$$name_field"] }
]
}
}
}],
as: "joined_result"
}},
{$unwind: {path: "$joined_result", preserveNullAndEmptyArrays: false}}
])
Please note that below is equivalent query in SQL:
SELECT * FROM t5
LEFT JOIN t6 ON (t5.age = t6.old AND t5.id = t6.no OR t5.name = t6.alias);
Where t5 and t6 are collections/tables and t5 has age, id and name columns/fields. Also, t6 has old, no and alias columns/fields.
What are possible ways to build this pipeline run time using MongoC driver API’s. The meaning of ‘run-time’ is that there can be different operations I mean multiple Join clauses. Different AND and OR combinations.
Is there any tool to build pipeline?