[DOCS-10791] Comment on: "manual/reference/operator/aggregation/lookup" Created: 14/Sep/17  Updated: 30/Oct/23  Resolved: 02/Jul/19

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

Type: Bug Priority: Major - P3
Reporter: Nathan Leniz Assignee: Kay Kim (Inactive)
Resolution: Fixed Votes: 1
Labels: collector-298ba4e7, docs-triage
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Issue Links:
Related
related to DOCS-10894 $lookup docs should mention the $look... Closed
Participants:
Days since reply: 4 years, 32 weeks, 1 day ago
Epic Link: DOCSP-1769

 Description   

Based on server ticket SERVER-22881, the text in $lookup documentation saying that an $unwind is necessary is no longer accurate.

$unwind may still be used for prettier formatting, but the same can be accomplished on the other side of the $lookup with $project and some other expressions.

Using the same sample documents in the document example, see the following pipeline and output.

db.orders.aggregate([
  {
     $lookup:
        {
           from: "inventory",
           localField: "specs",
           foreignField: "size",
           as: "inventory_docs"
       }
  },
  {
     $match: { "inventory_docs": { $ne: [] } }
  }
])

{
	"_id" : 1,
	"item" : "MON1003",
	"price" : 350,
	"quantity" : 2,
	"specs" : [
		"27 inch",
		"Retina display",
		"1920x1080"
	],
	"type" : "Monitor",
	"inventory_docs" : [
		{
			"_id" : 1,
			"sku" : "MON1003",
			"type" : "Monitor",
			"instock" : 120,
			"size" : "27 inch",
			"resolution" : "1920x1080"
		}
	]
}



 Comments   
Comment by Githook User [ 02/Jul/19 ]

Author:

{'name': 'Kay Kim', 'username': 'kay-kim', 'email': 'kay.kim@10gen.com'}

Message: DOCS-10791, DOCS-10246: localField is an array, mention / on data-model-design
Branch: v3.4
https://github.com/mongodb/docs/commit/e982d089fc7313d7730b0b43934e84b1e8a6d0df

Comment by Githook User [ 02/Jul/19 ]

Author:

{'name': 'Kay Kim', 'username': 'kay-kim', 'email': 'kay.kim@10gen.com'}

Message: DOCS-10791, DOCS-10246: $lookup localField is an array, mention $lookup/$graphlookup on data-model-design
Branch: v3.6
https://github.com/mongodb/docs/commit/7c4264c55ecbee1537aaf7c9f3994626aa332b10

Comment by Githook User [ 02/Jul/19 ]

Author:

{'name': 'Kay Kim', 'username': 'kay-kim', 'email': 'kay.kim@10gen.com'}

Message: DOCS-10791, DOCS-10246: $lookup localField is an array, mention $lookup/$graphlookup on data-model-design
Branch: v4.0
https://github.com/mongodb/docs/commit/db4fd68d948f1257efbc88593838fbb7d2d4ffad

Comment by Githook User [ 02/Jul/19 ]

Author:

{'name': 'Kay Kim', 'email': 'kay.kim@10gen.com', 'username': 'kay-kim'}

Message: DOCS-10791, DOCS-10246: $lookup localField is an array, mention $lookup/$graphlookup on data-model-design
Branch: master
https://github.com/mongodb/docs/commit/e471eb5517c445d7647114e3c123ef1564560441

Comment by Asya Kamsky [ 28/Nov/17 ]

I was about to mention the same thing for that page.

You do NOT need an $unwind and that note/example should be adjusted.

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