Skip to content

Commit 2e5b02b

Browse files
DOCS-15300 Add lookup and unionwith (#1306)
* DOCS-15300 Add lookup and unionwith * DOCSP-15300 updates for feedback * DOCSP-15300 included searchMeta restrictions
1 parent 6ca0b7f commit 2e5b02b

File tree

2 files changed

+112
-43
lines changed

2 files changed

+112
-43
lines changed

source/reference/operator/aggregation/lookup.txt

Lines changed: 60 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -410,33 +410,70 @@ the ``pipeline`` field.
410410
Atlas Search Support
411411
~~~~~~~~~~~~~~~~~~~~
412412

413-
Starting in v6.0, the ``pipeline`` can contain the :atlas:`Atlas Search
414-
</atlas-search>` :pipeline:`$search` stage as the first stage inside
415-
the pipeline.
413+
Starting in MongoDB 6.0, you can specify the :atlas:`Atlas Search
414+
</atlas-search>` :pipeline:`$search` or :pipeline:`$searchMeta` stage
415+
in the ``$lookup`` pipeline to search collections on the Atlas
416+
cluster. The :pipeline:`$search` or the :pipeline:`$searchMeta` stage
417+
must be the first stage inside the ``$lookup`` pipeline.
416418

417419
For example, when you :ref:`lookup-syntax-let-pipeline` or run
418420
:ref:`lookup-syntax-concise-correlated-subquery`, you can specify
419-
:pipeline:`$search` inside the pipeline as shown below:
420-
421-
.. code-block::
422-
:copyable: false
423-
:emphasize-lines: 7-11
424-
425-
[{
426-
"$lookup": {
427-
"from": <joined collection>,
428-
"let": {<var_n>: <expression>, ...},
429-
"as": <output array field>,
430-
"pipeline": [{
431-
"$search": {
432-
"<operator>": {
433-
<operator-specification>
421+
:pipeline:`$search` or :pipeline:`$searchMeta` inside the pipeline as
422+
shown below:
423+
424+
.. tabs::
425+
426+
.. tab:: $search
427+
:tabid: search
428+
429+
.. code-block::
430+
:copyable: false
431+
:emphasize-lines: 7-11
432+
433+
[{
434+
"$lookup": {
435+
"from": <joined collection>,
436+
localField: <field from the input documents>,
437+
foreignField: <field from the documents of the "from" collection>,
438+
"as": <output array field>,
439+
"pipeline": [{
440+
"$search": {
441+
"<operator>": {
442+
<operator-specification>
443+
}
444+
},
445+
...
446+
}]
434447
}
435-
},
436-
...
437-
}]
438-
}
439-
}]
448+
}]
449+
450+
.. tab:: $searchMeta
451+
:tabid: searchmeta
452+
453+
.. code-block::
454+
:copyable: false
455+
:emphasize-lines: 7-11
456+
457+
[{
458+
"$lookup": {
459+
"from": <joined collection>,
460+
localField: <field from the input documents>,
461+
foreignField: <field from the documents of the "from" collection>,
462+
"as": <output array field>,
463+
"pipeline": [{
464+
"$searchMeta": {
465+
"<collector>": {
466+
<collector-specification>
467+
}
468+
},
469+
...
470+
}]
471+
}
472+
}]
473+
474+
To see an example of :pipeline:`$lookup` with :pipeline:`$search`,
475+
see the Atlas Search tutorial :atlas:`Run an Atlas Search $search Query
476+
Using $lookup </atlas-search/tutorial/lookup-with-search/>`.
440477

441478
.. _lookup-sharded-collections:
442479

source/reference/operator/aggregation/unionWith.txt

Lines changed: 52 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -212,27 +212,59 @@ top-level collection/view on which the
212212
Atlas Search Support
213213
~~~~~~~~~~~~~~~~~~~~
214214

215-
Starting in v6.0, the ``pipeline`` can contain the :atlas:`Atlas Search
216-
</atlas-search>` :pipeline:`$search` stage as the first stage inside
217-
the pipeline.
218-
219-
.. code-block::
220-
:copyable: false
221-
:emphasize-lines: 5-9
222-
223-
[{
224-
"$unionWith": {
225-
"coll": <collection-name>,
226-
"pipeline": [{
227-
"$search": {
228-
"<operator>": {
229-
<operator-specification>
215+
Starting in MongoDB 6.0, you can specify the :atlas:`Atlas Search
216+
</atlas-search>` :pipeline:`$search` or :pipeline:`$searchMeta` stage
217+
in the ``$unionWith`` pipeline to search collections on the Atlas
218+
cluster. The :pipeline:`$search` or the :pipeline:`$searchMeta` stage
219+
must be the first stage inside the ``$unionWith`` pipeline.
220+
221+
.. tabs::
222+
223+
.. tab:: $search
224+
:tabid: search
225+
226+
.. code-block::
227+
:copyable: false
228+
:emphasize-lines: 5-9
229+
230+
[{
231+
"$unionWith": {
232+
"coll": <collection-name>,
233+
"pipeline": [{
234+
"$search": {
235+
"<operator>": {
236+
<operator-specification>
237+
}
238+
},
239+
...
240+
}]
230241
}
231-
},
232-
...
233-
}]
234-
}
235-
}]
242+
}]
243+
244+
.. tab:: $searchMeta
245+
:tabid: searchmeta
246+
247+
.. code-block::
248+
:copyable: false
249+
:emphasize-lines: 5-9
250+
251+
[{
252+
"$unionWith": {
253+
"coll": <collection-name>,
254+
"pipeline": [{
255+
"$searchMeta": {
256+
"<collector>": {
257+
<collector-specification>
258+
}
259+
},
260+
...
261+
}]
262+
}
263+
}]
264+
265+
To see an example of :pipeline:`$unionWith` with :pipeline:`$search`,
266+
see the Atlas Search tutorial :atlas:`Run an Atlas Search $search Query
267+
Using $unionWith </atlas-search/tutorial/search-with-unionwith/>`.
236268

237269
Restrictions
238270
~~~~~~~~~~~~

0 commit comments

Comments
 (0)