Skip to Main Content

MongoByte MongoDB Logo

Welcome to the new MongoDB Feedback Portal!

{Improvement: "Your idea"}
We’ve upgraded our system to better capture and act on your feedback.
Your feedback is meaningful and helps us build better products.

Status Submitted
Categories Database
Created by Guest
Created on Apr 6, 2021

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.
  • Attach files
  • Guest
    Jun 15, 2021
    I see, thanks for explanation.
  • Guest
    Jun 14, 2021
    (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