[DOCS-12544] [Server] Add multiple $lookup example Created: 13/Mar/19  Updated: 30/Oct/23  Resolved: 20/Jan/23

Status: Closed
Project: Documentation
Component/s: manual, Server
Affects Version/s: None
Fix Version/s: Server_Docs_20231030

Type: Task Priority: Trivial - P5
Reporter: Harshad Dhavale Assignee: Unassigned
Resolution: Won't Fix Votes: 0
Labels: proactive
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:
Days since reply: 1 year, 2 weeks, 5 days ago

 Description   

It is possible to perform multiple $lookups in a single query, on the same collection, on fields that are derived using $addFields. A suggestion was made in a case that perhaps our documentation could be updated to indicate this. For example a query like this is possible:

{$match: {id: {$in: [/^123456/ ,
/^123457/
]}}},
{"$addFields":{
"BlockKey": {$concat: [ "L", { $substr: [ "$id", 0, 7 ]}] },
"CodeKey": {$concat: [ "L", { $substr: [ "$_id", 0, 6 ]},"A"] }
}},
{ $lookup: {
from: "port_ss_col",
localField: "BlockKey",
foreignField: "_id",
as: "BlockArray"
}},
{ $lookup: {
from: "port_ss_col",
localField: "CodeKey",
foreignField: "_id",
as: "CodeArray"
}},
{ $project: {...

 

If that's not possible (or if this doc-addition doesn't make sense), that's fine; it's understood that every query use case cannot be included in our documentation. This was just a suggestion that we received.



 Comments   
Comment by Ashley Brown [ 20/Jan/23 ]

Closing; we believe this is covered adequately, but please feel free to reopen if you disagree.

Generated at Thu Feb 08 08:05:30 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.