Hi,
It sounds like you’re trying to build a MongoDB query using a string, then executing that string using db.eval() similar to building an SQL query. Is this correct?
Note that unlike SQL, MongoDB query language was designed with driver usage in mind, so you should be able to programmatically build an aggregation pipeline without resorting to putting strings together.
Could you provide a concrete example of what you mean by “dynamic number of lookups” and why you think it cannot be done programmatically? What are the relevant fields, and what output are you expecting?
Please also post your MongoDB version and your driver version.
Best regards
Kevin