<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>MongoDB on</title><link>https://tonny0531.github.io/categories/mongodb/</link><description>Recent content in MongoDB on</description><generator>Hugo -- gohugo.io</generator><lastBuildDate>Fri, 18 Mar 2022 15:54:51 +0800</lastBuildDate><atom:link href="https://tonny0531.github.io/categories/mongodb/index.xml" rel="self" type="application/rss+xml"/><item><title>MongoDb Lookup 使用紀錄</title><link>https://tonny0531.github.io/post/mongodb/lookup/</link><pubDate>Fri, 18 Mar 2022 15:54:51 +0800</pubDate><guid>https://tonny0531.github.io/post/mongodb/lookup/</guid><description>主旨 最近幾天工作上都在使用 MongoDB，但常常忘記一些指令的格式
因此特別紀錄一下，並說明一下怎麼使用
Lookup 在 MongoDB 初期並沒有所謂的 Join
只有單純的 Collection Search
但由於單一文本最大限制 16MB 的存在 And 物件管理上的設計
而衍伸出了 Lookup 這個 Operator
可以理解成他就是 Sql 的 Join
{ $lookup: { from: &amp;lt;foreign collection&amp;gt;, localField: &amp;lt;field from local collection's documents&amp;gt;, foreignField: &amp;lt;field from foreign collection's documents&amp;gt;, let: { &amp;lt;var_1&amp;gt;: &amp;lt;expression&amp;gt;, …, &amp;lt;var_n&amp;gt;: &amp;lt;expression&amp;gt; }, pipeline: [ &amp;lt;pipeline to run&amp;gt; ], as: &amp;lt;output array field&amp;gt; } } from: 關聯到哪個Collection localField: 當前Collection的欄位名稱 foreignField: 關聯到Collection的欄位名稱 let: 相當於 Sql 的要甚麼欄位並且命名 pipeline: 可以在關聯到的資料庫多做一次Pipline Ex: $match、$gt(e)&amp;hellip;.</description></item></channel></rss>