1818
1919|out| takes documents returned by the aggregation pipeline and writes
2020them to a specified collection. The |out| operator must be the last
21- stage in the
22- :manual:`aggregation pipeline </reference/operator/aggregation-pipeline/>`.
23- In {+adl+}, you can use |out| to write data from any one of the
24- :ref:`supported <datalake-configuration-file-overview>` {+data-lake-stores+}
25- or multiple :ref:`supported <datalake-configuration-file-overview>`
26- {+data-lake-stores+} when using :ref:`federated queries <federated-queries>`
27- to any one of the following:
21+ stage in the :manual:`aggregation pipeline
22+ </reference/operator/aggregation-pipeline/>`. In {+adl+}, you can use
23+ |out| to write data from any one of the :ref:`supported
24+ <datalake-configuration-file-overview>` {+data-lake-stores+} or
25+ multiple :ref:`supported <datalake-configuration-file-overview>`
26+ {+data-lake-stores+} when using :ref:`federated queries
27+ <federated-queries>` to any one of the following:
2828
2929- |s3| buckets with read and write permissions
3030- |service| cluster :manual:`namespace
@@ -302,6 +302,40 @@ Fields
302302 the ID of the project that contains your {+dl+}.
303303 - Optional
304304
305+ .. _adl-out-stage-options:
306+
307+ Options
308+ -------
309+
310+ .. list-table::
311+ :header-rows: 1
312+ :widths: 20 10 60 10
313+
314+ * - Option
315+ - Type
316+ - Description
317+ - Necessity
318+
319+ * - ``background``
320+ - boolean
321+ - For |out| to |s3| only.
322+
323+ Flag to run aggregation operations in the background. If
324+ omitted, defaults to ``false``. When set to ``true``, {+adl+}
325+ runs the queries in the background.
326+
327+ .. code-block:: json
328+ :copyable: false
329+
330+ { "background" : true }
331+
332+ Use this option if you want to submit other new queries without
333+ waiting for currently running queries to complete or disconnect
334+ your {+dl+} connection while the queries continue to run in the
335+ background.
336+
337+ - Optional
338+
305339.. _adl-out-stage-egs:
306340
307341Examples
@@ -313,12 +347,14 @@ Examples
313347 .. tab:: S3
314348 :tabid: s3
315349
350+ **Create a Filename**
351+
316352 The following examples show |out| syntaxes for dynamically
317353 creating a filename from a constant string or from the fields of
318354 the same or different data types in the documents that reach the
319355 |out| stage.
320356
321- ** Simple String Example* *
357+ *Simple String Example*
322358
323359 .. example::
324360
@@ -373,7 +409,7 @@ Examples
373409 ``big_box_store/3.bson.gz`` through
374410 ``big_box_store/5.bson.gz``.
375411
376- ** Single Field from Documents* *
412+ *Single Field from Documents*
377413
378414 .. example::
379415
@@ -405,7 +441,7 @@ Examples
405441 documents' ``sale-date`` value converted to a string.
406442
407443
408- ** Multiple Fields from Documents* *
444+ *Multiple Fields from Documents*
409445
410446 .. example::
411447
@@ -452,7 +488,7 @@ Examples
452488 the documents' ``name`` and ``unique-id`` values.
453489
454490
455- ** Multiple Types of Fields from Documents* *
491+ *Multiple Types of Fields from Documents*
456492
457493 .. example::
458494
@@ -490,9 +526,9 @@ Examples
490526 }
491527
492528 |out| writes 154 MiB of data to compressed |json| files, where
493- each file contains all documents with the same ``store-number``,
494- ``sale-date``, and ``part-id`` values. To name each file, |out|
495- concatenates:
529+ each file contains all documents with the same
530+ ``store-number``, `` sale-date``, and ``part-id`` values. To
531+ name each file, |out| concatenates:
496532
497533 - A constant string value of ``big-box-store/``,
498534 - A string value of a unique store number in the
@@ -503,6 +539,37 @@ Examples
503539 - A string value of part ID from the ``part-id`` field, and
504540 - A forward slash (``/``).
505541
542+ **Run Query in the background**
543+
544+ The following example shows |out| syntax for running an
545+ aggregation pipeline that ends with the |out| stage in the
546+ background.
547+
548+ .. code-block:: json
549+ :emphasize-lines: 16
550+
551+ db.foo.aggregate([
552+ {
553+ "$out" : {
554+ "s3" : {
555+ "bucket" : "my-s3-bucket",
556+ "region" : "us-east-1",
557+ "filename" : {
558+ "$toString" : "$sale-date"
559+ },
560+ "format" : {
561+ "name" : "json"
562+ }
563+ }
564+ }
565+ }
566+ ], { background: true })
567+
568+ |out| writes to |json| files in the root of the bucket in the
569+ background. Each |json| file contains all of the documents
570+ with the same ``sale-date`` value. |out| names each file using
571+ the documents' ``sale-date`` value converted to a string.
572+
506573 .. tab:: Atlas Cluster
507574 :tabid: atlas
508575
@@ -598,6 +665,7 @@ Examples
598665
599666.. seealso::
600667
601- - :manual:`$out Aggregation Stage Reference </reference/operator/aggregation/out>`
668+ - :manual:`$out Aggregation Stage Reference
669+ </reference/operator/aggregation/out>`
602670 - `Tutorial: Federated Queries and $out to S3
603671 <https://developer.mongodb.com/how-to/atlas-data-lake-federated-queries-out-aws-s3>`__
0 commit comments