Skip to content

Commit c34842e

Browse files
mongoKartrustagir
andauthored
Docsp 27977 - documents stage (#334)
* wip * remove css * Apply suggestions from code review * mk feedback --------- Co-authored-by: Rea Rustagi <[email protected]>
1 parent 2e0bb0c commit c34842e

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed

source/fundamentals/builders/aggregates.txt

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
Aggregates Builders
33
===================
44

5-
.. default-domain:: mongodb
6-
75
.. contents:: On this page
86
:local:
97
:backlinks: none
@@ -73,7 +71,6 @@ The following example creates a pipeline stage that matches all documents where
7371
:dedent:
7472

7573

76-
7774
Project
7875
-------
7976

@@ -110,6 +107,34 @@ into a new field called ``rating``, effectively renaming the field.
110107
:dedent:
111108

112109

110+
Documents
111+
---------
112+
113+
Use the ``documents()`` method to create a
114+
:manual:`$documents </reference/operator/aggregation/documents/>`
115+
pipeline stage that returns literal documents from input values.
116+
117+
.. important::
118+
119+
If you use a ``$documents`` stage in an aggregation pipeline, it must be the first
120+
stage in the pipeline.
121+
122+
The following example creates a pipeline stage that creates
123+
sample documents with a ``title`` field:
124+
125+
.. literalinclude:: /includes/fundamentals/code-snippets/builders/AggBuilders.java
126+
:start-after: // begin documents
127+
:end-before: // end documents
128+
:language: java
129+
:dedent:
130+
131+
.. important::
132+
133+
If you use the ``documents()`` method to provide the input to an aggregation pipeline,
134+
you must call the ``aggregate()`` method on a database instead of on a
135+
collection.
136+
137+
113138
Sample
114139
------
115140

@@ -946,3 +971,4 @@ aggregation stage:
946971

947972
Learn more about this helper from the
948973
`searchMeta() API documentation <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/Aggregates.html#searchMeta(com.mongodb.client.model.search.SearchCollector)>`__.
974+

source/includes/fundamentals/code-snippets/builders/AggBuilders.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,4 +302,13 @@ private void matchStage() {
302302
match(eq("title", "The Shawshank Redemption"));
303303
// end match
304304
}
305+
306+
private void documents() {
307+
// begin documents
308+
documents(asList(
309+
new Document("title", "The Shawshank Redemption"),
310+
new Document("title", "Back to the Future"),
311+
new Document("title", "Jurassic Park")));
312+
// end documents
313+
}
305314
}

source/index.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,7 @@ Take the free online course taught by MongoDB instructors
161161

162162
.. list-table::
163163

164-
* - .. cssclass:: bordered-figure
165-
.. figure:: /includes/figures/M220J_hero.jpg
164+
* - .. figure:: /includes/figures/M220J_hero.jpg
166165
:alt: MongoDB Java Course Hero
167166

168167
- `Using MongoDB with Java <https://learn.mongodb.com/learning-paths/using-mongodb-with-java>`_

0 commit comments

Comments
 (0)