18
18
19
19
|out| takes documents returned by the aggregation pipeline and writes
20
20
them 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:
28
28
29
29
- |s3| buckets with read and write permissions
30
30
- |service| cluster :manual:`namespace
@@ -302,6 +302,40 @@ Fields
302
302
the ID of the project that contains your {+dl+}.
303
303
- Optional
304
304
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
+
305
339
.. _adl-out-stage-egs:
306
340
307
341
Examples
@@ -313,12 +347,14 @@ Examples
313
347
.. tab:: S3
314
348
:tabid: s3
315
349
350
+ **Create a Filename**
351
+
316
352
The following examples show |out| syntaxes for dynamically
317
353
creating a filename from a constant string or from the fields of
318
354
the same or different data types in the documents that reach the
319
355
|out| stage.
320
356
321
- ** Simple String Example* *
357
+ *Simple String Example*
322
358
323
359
.. example::
324
360
@@ -373,7 +409,7 @@ Examples
373
409
``big_box_store/3.bson.gz`` through
374
410
``big_box_store/5.bson.gz``.
375
411
376
- ** Single Field from Documents* *
412
+ *Single Field from Documents*
377
413
378
414
.. example::
379
415
@@ -405,7 +441,7 @@ Examples
405
441
documents' ``sale-date`` value converted to a string.
406
442
407
443
408
- ** Multiple Fields from Documents* *
444
+ *Multiple Fields from Documents*
409
445
410
446
.. example::
411
447
@@ -452,7 +488,7 @@ Examples
452
488
the documents' ``name`` and ``unique-id`` values.
453
489
454
490
455
- ** Multiple Types of Fields from Documents* *
491
+ *Multiple Types of Fields from Documents*
456
492
457
493
.. example::
458
494
@@ -490,9 +526,9 @@ Examples
490
526
}
491
527
492
528
|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:
496
532
497
533
- A constant string value of ``big-box-store/``,
498
534
- A string value of a unique store number in the
@@ -503,6 +539,37 @@ Examples
503
539
- A string value of part ID from the ``part-id`` field, and
504
540
- A forward slash (``/``).
505
541
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
+
506
573
.. tab:: Atlas Cluster
507
574
:tabid: atlas
508
575
@@ -598,6 +665,7 @@ Examples
598
665
599
666
.. seealso::
600
667
601
- - :manual:`$out Aggregation Stage Reference </reference/operator/aggregation/out>`
668
+ - :manual:`$out Aggregation Stage Reference
669
+ </reference/operator/aggregation/out>`
602
670
- `Tutorial: Federated Queries and $out to S3
603
671
<https://developer.mongodb.com/how-to/atlas-data-lake-federated-queries-out-aws-s3>`__
0 commit comments