Skip to content

Commit 941dffe

Browse files
authored
Add reference docs for explain of find and aggregate (#626)
JAVA-3909
1 parent 5008b2a commit 941dffe

File tree

6 files changed

+94
-1
lines changed

6 files changed

+94
-1
lines changed

docs/reference/content/driver-reactive/tutorials/aggregation.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,21 @@ collection.aggregate(
9393
)
9494
).subscribe(new PrintDocumentSubscriber());
9595
```
96+
97+
### Explain an Aggregation
98+
99+
To [explain]({{< docsref "reference/command/explain/" >}}) an aggregation pipeline, call the
100+
[`AggregatePublisher.explain()`]({{< apiref "mongodb-driver-reactivestreams" "com/mongodb/reactivestreams/client/AggregatePublisher.html#explain()"
101+
> >}})
102+
method:
103+
104+
```java
105+
collection.aggregate(
106+
Arrays.asList(
107+
Aggregates.match(Filters.eq("categories", "Bakery")),
108+
Aggregates.group("$stars", Accumulators.sum("count", 1))))
109+
.explain()
110+
.subscribe(new PrintDocumentSubscriber());
111+
```
112+
113+
The driver supports explain of aggregation pipelines starting with MongoDB 3.6.

docs/reference/content/driver-reactive/tutorials/perform-read-operations.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,20 @@ collection.find(and(gte("stars", 2), lt("stars", 5), eq("categories", "Bakery"))
170170
.subscribe(new PrintDocumentSubscriber());
171171
```
172172

173+
### Explain
174+
175+
To [explain]({{< docsref "reference/command/explain/" >}}) a find operation, call the
176+
[`FindPublisher.explain()`]({{< apiref "mongodb-driver-reactivestreams" "com/mongodb/reactivestreams/client/FindPublisher.html#explain()" >}})
177+
method:
178+
179+
```java
180+
collection.find(and(gte("stars", 2), lt("stars", 5), eq("categories", "Bakery")))
181+
.explain()
182+
.subscribe(new PrintDocumentSubscriber());
183+
```
184+
185+
The driver supports explain of find operations starting with MongoDB 3.0.
186+
173187
## Read Preference
174188

175189
For read operations on [replica sets]({{<docsref "replication/" >}}) or [sharded clusters]({{<docsref "sharding/" >}}), applications can configure the [read preference]({{<docsref "reference/read-preference" >}}) at three levels:

docs/reference/content/driver-scala/tutorials/aggregation.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,20 @@ collection.aggregate(
8686
)
8787
).printResults()
8888
```
89+
90+
### Explain an Aggregation
91+
92+
To [explain]({{< docsref "reference/command/explain/" >}}) an aggregation pipeline, call the
93+
[`AggregateObservable.explain()`]({{< apiref "mongo-scala-driver" "org/mongodb/scala/AggregateObservable.html#explain()" >}})
94+
method:
95+
96+
```java
97+
collection.aggregate(
98+
Arrays.asList(
99+
Aggregates.match(Filters.eq("categories", "Bakery")),
100+
Aggregates.group("$stars", Accumulators.sum("count", 1))))
101+
.explain()
102+
.printResults()
103+
```
104+
105+
The driver supports explain of aggregation pipelines starting with MongoDB 3.6.

docs/reference/content/driver-scala/tutorials/perform-read-operations.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,20 @@ collection.find(and(gte("stars", 2), lt("stars", 5), equal("categories", "Bakery
156156
.printResults()
157157
```
158158

159+
### Explain
160+
161+
To [explain]({{< docsref "reference/command/explain/" >}}) a find operation, call the
162+
[`FindObservable.explain()`]({{< apiref "mongo-scala-driver" "org/mongodb/scala/FindObservable.html#explain()" >}})
163+
method:
164+
165+
```scala
166+
collection.find(and(gte("stars", 2), lt("stars", 5), eq("categories", "Bakery")))
167+
.explain()
168+
.printResults()
169+
```
170+
171+
The driver supports explain of find operations starting with MongoDB 3.0.
172+
159173
## Read Preference
160174

161175
For read operations on [replica sets]({{<docsref "replication/" >}}) or [sharded clusters]({{<docsref "sharding/" >}}), applications can configure the [read preference]({{<docsref "reference/read-preference" >}}) at three levels:
@@ -240,7 +254,7 @@ For example, in the following, the `collWithReadConcern` instance has an AVAILAB
240254

241255
```scala
242256
val collWithReadConcern = collection.withReadConcern(ReadConcern.AVAILABLE)
243-
```
257+
```
244258

245259
You can build `MongoClientSettings`, `MongoDatabase`, or `MongoCollection` to include a combination of read concern, read preference, and [write concern]({{<docsref "reference/write-concern" >}}).
246260

docs/reference/content/driver/tutorials/aggregation.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,20 @@ collection.aggregate(
100100
)
101101
).forEach(printBlock);
102102
```
103+
104+
### Explain an Aggregation
105+
106+
To [explain]({{< docsref "reference/command/explain/" >}}) an aggregation pipeline, call the
107+
[`AggregateIterable.explain()`]({{< apiref "mongodb-driver-sync" "com/mongodb/client/AggregateIterable.html#explain()" >}}) method:
108+
109+
```java
110+
Document explainResult = collection.aggregate(
111+
Arrays.asList(
112+
Aggregates.match(Filters.eq("categories", "Bakery")),
113+
Aggregates.group("$stars", Accumulators.sum("count", 1))))
114+
.explain();
115+
System.out.println(explainResult.toJson(JsonWriterSettings.builder().indent(true).build()));
116+
```
117+
118+
The driver supports explain of aggregation pipelines starting with MongoDB 3.6.
119+

docs/reference/content/driver/tutorials/perform-read-operations.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,19 @@ collection.find(and(gte("stars", 2), lt("stars", 5), eq("categories", "Bakery"))
178178
.forEach(printConsumer);
179179
```
180180

181+
182+
### Explain
183+
184+
To [explain]({{< docsref "reference/command/explain/" >}}) a find operation, call the
185+
[`FindIterable.explain()`]({{< apiref "mongodb-driver-sync" "com/mongodb/client/FindIterable.html#explain()" >}}) method:
186+
187+
```java
188+
Document explainResult = collection.find(and(gte("stars", 2), lt("stars", 5), eq("categories", "Bakery"))).explain();
189+
System.out.println(explainResult.toJson(JsonWriterSettings.builder().indent(true).build()));
190+
```
191+
192+
The driver supports explain of find operations starting with MongoDB 3.0.
193+
181194
## MongoIterable
182195

183196
The [`MongoIterable`]({{< apiref "mongodb-driver-sync" "com/mongodb/client/MongoIterable.html" >}}) interface provides helper methods to access the results of an operation:

0 commit comments

Comments
 (0)