Pass document field to $loolup.from and $lookup.as
Suppose I have collection of documents { entityId, entity }, where entity is names of other collections I would like to make aggregation with lookup and be able to pass entity value to $lookup from and as
db.collection.aggregation([{ $lookup: { from: '$entity', let: { entityId: '$entityId' }, pipeline: [{ $match: { $expr: { $eq: ['$_id', '$$entityId'] } } }], as: '$entity' } }])
As of mongo v4.4.4 that seems not working.
-
Ivan CHERVIAKOV commented
I see, thanks for explanation.
-
(moved this request to the Database section)
You are correct, this would not work, `from` and `as` only accept static strings. There are no short-term plans to support this feature, it would require a revamp of the security model and query optimization.
A similar request is also tracked here https://jira.mongodb.org/browse/SERVER-22497