[SERVER-5048] $project to have ability to get data from referenced collections (SQL-like "join") Created: 23/Feb/12  Updated: 25/Jun/15  Resolved: 25/Jun/15

Status: Closed
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Major - P3
Reporter: Richard Minney Assignee: Unassigned
Resolution: Duplicate Votes: 4
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-19095 $lookup Closed
Participants:

 Description   

Aggregation framework looks very promising for manipulation of results from read query prior to passing back to the client. It would be great if a facility similar to SQL: "fields:

{ collection1.field1, collection2.field2 }

, joinOn:

{ collection1.refSourceField, collection2.refTargetField }

was available. In effect the syntax for $join or similar would have the developer specify:

  • What field they want to get from a target or referenced collection
  • What field in their source collection has a look-up to the target collection
  • What field in the target collection is referenced from the source.

Obviously this is only useful in cases where data is not denormalized...enterprise systems with large numbers of master data updates cannot denormalize fully because of the pain of mass updates. For example if we have two collections:

1. Employee.ID = mongoID & Employee.name.fullName = "Fred Flintstone"
2. Project.ID = mongoID & Project.responsibleMgr = mongoID of the employee who is the project manager
(assume Employee.name.fullName is not denormalized because it is referenced many times and people get married/change names)

When reading the Project collection we can only get the mongo ID of the project mgr which is not that useful. If the client does a second read of Employee where ID = Project.responsibleMgr to get their name this is ok but extra burden on the client-ui developer and two http requests. Of course a custom api on the server would avoid the two http requests but is again more work.

It would be great if in this example we can use $join notation to say something like "fields:

{ Project.ID, Project.responsibleMgr, Employee.name.fullName }

, joinOn:

{ Employee.ID, Project.responsibleMgr }

" and get everything back at once from one query.



 Comments   
Comment by Ian Whalen (Inactive) [ 25/Jun/15 ]

Hi Richard, thanks a lot for filing this feature request and my apologies for the time since it was last updated.

I'm going to close this as a Duplicate and link it to our upcoming $lookup feature - we’ve decided to progress along fairly similar lines of your suggestion and provide users with the desired functionality via this new operator in the aggregation pipeline. Please follow along in SERVER-19095 for further details of the $lookup implementation.

Generated at Thu Feb 08 03:07:44 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.