8000 DOCSP-33297: fix link to Helpers.scala and mention its use in code co… · rustagir/docs-java-other@8c71015 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8c71015

Browse files
author
Chris Cho
authored
DOCSP-33297: fix link to Helpers.scala and mention its use in code comments (mongodb#32)
* DOCSP-33297: fix link to Helpers.java and mention its use in code comments
1 parent b02006f commit 8c71015

File tree

11 files changed

+56
-8
lines changed

11 files changed

+56
-8
lines changed

reference/content/driver-scala/getting-started/quick-start-primer.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ be taken to ensure that the `Observer` has the capacity to handle all the result
6262

6363
## Helpers used in the Quick Tour
6464

65-
For the Quick Tour we use custom implicit helpers defined in [`Helpers.scala`]({{< srcref "driver-scala/src/it/scala/tour/Helpers.scala" >}}).
65+
For the Quick Tour we use custom implicit helpers defined in [`Helpers.scala`]({{< srcref "driver-scala/src/integration/scala/tour/Helpers.scala" >}}).
6666
These helpers get and print results and although this is an artificial scenario for asynchronous code we block on the results of one
6767
example before starting the next, so as to ensure the state of the database. The `Helpers` object
6868
provides the following methods:
@@ -81,4 +81,4 @@ provides the following methods:
8181

8282
* printHeadResult()
8383

84-
Blocks until the first result of the `Observable` is available and then prints it.
84+
Blocks until the first result of the `Observable` is available and then prints it.

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ In the following example, the aggregation pipeline
5656

5757
- Then, uses a [`$group`]({{< docsref "reference/operator/aggregation/group/" >}}) stage to group the matching documents by the `stars` field, accumulating a count of documents for each distinct value of `stars`. The example uses [`Aggregates.group`]({{< relref "builders/aggregation.md#group" >}}) to build the `$group` stage and [`Accumulators.sum`]({{< apiref "mongo-scala-driver" "org/mongodb/scala/model/Accumulators$.html#sum[TExpression](fieldName:String,expression:TExpression):org.mongodb.scala.model.BsonField" >}}) to build the [accumulator expression]({{< docsref "reference/operator/aggregation/group/#accumulator-operator" >}}). For the [accumulator expressions]({{< docsref "reference/operator/aggregation-group/" >}}) for use within the [`$group`]({{< docsref "reference/operator/aggregation/group/" >}}) stage, the Scala driver provides [`Accumulators`]({{< apiref "mongodb-driver-core" "com/mongodb/client/model/Accumulators.html" >}}) helper class.
5858
```scala
59+
// Note: this code example uses a custom implicit helper referenced in the Quick Start Primer
5960
collection.aggregate(Seq(
6061
Aggregates.filter(Filters.equal("categories", "Bakery")),
6162
Aggregates.group("$stars", Accumulators.sum("count", 1))
@@ -71,6 +72,7 @@ In the following example, the aggregation pipeline uses a [`$project`]({{< docsr
7172

7273

7374
```scala
75+
// Note: this code example uses a custom implicit helper referenced in the Quick Start Primer
7476
collection.aggregate(
7577
Seq(
7678
Aggregates.project(
@@ -93,13 +95,13 @@ To [explain]({{< docsref "reference/command/explain/" >}}) an aggregation pipeli
9395
[`AggregateObservable.explain()`]({{< apiref "mongo-scala-driver" "org/mongodb/scala/AggregateObservable.html#explain()" >}})
9496
method:
9597

96-
```java
98+
```scala
99+
// Note: this code example uses a custom implicit helper referenced in the Quick Start Primer
97100
collection.aggregate(
98-
Arrays.asList(
99-
Aggregates.match(Filters.eq("categories", "Bakery")),
100-
Aggregates.group("$stars", Accumulators.sum("count", 1))))
101-
.explain()
102-
.printResults()
101+
Seq(Aggregates.filter(Filters.eq("categories", "Bakery")),
102+
Aggregates.group("$stars", Accumulators.sum("count", 1))))
103+
.explain()
104+
.printResults()
103105
```
104106

105107
The driver supports explain of aggregation pipelines starting with MongoDB 3.6.

reference/content/driver-scala/tutorials/bulk-writes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ This guide uses the `Observable` implicits as covered in the [Quick Start Primer
2525
{{% /note %}}
2626

2727
```scala
28+
// Note: this code example uses a custom implicit helper referenced in the Quick Start Primer
2829
import org.mongodb.scala._
2930
import org.mongodb.scala.model._
3031

reference/content/driver-scala/tutorials/commands.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ object that specifies the command and pass it to the `runCommand()` method.
4747
The following sample code runs the [`buildInfo`]({{<docsref "reference/command/buildInfo" >}}) command and prints the results:
4848

4949
```scala
50+
// Note: this code example uses a custom implicit helper referenced in the Quick Start Primer
5051
database.runCommand(Document("buildInfo" -> 1)).printResults()
5152
```
5253

reference/content/driver-scala/tutorials/databases-collections.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ The MongoDB driver provides the [`createCollection()`]({{< apiref "mongo-scala-d
8383
For example, the following operation creates a [capped collection]({{<docsref "core/capped-collections" >}}) sized to 1 megabyte:
8484

8585
```scala
86+
// Note: this code example uses a custom implicit helper referenced in the Quick Start Primer
8687
database.createCollection("cappedCollection", CreateCollectionOptions().capped(true).sizeInBytes(0x100000))
8788
.printResults()
8889
```
@@ -92,6 +93,7 @@ database.createCollection("cappedCollection", CreateCollectionOptions().capped(t
9293
MongoDB provides the capability to [validate documents]({{<docsref "core/document-validation" >}}) during updates and insertions. Validation rules are specified on a per-collection basis using the [`ValidationOptions`]({{< apiref "mongo-scala-driver" "org/mongodb/scala/model/package$$ValidationOptions$.html" >}}), which takes a filter document that specifies the validation rules or expressions.
9394

9495
```scala
96+
// Note: this code example uses a custom implicit helper referenced in the Quick Start Primer
9597
ValidationOptions collOptions = ValidationOptions().validator(
9698
Filters.or(Filters.exists("email"), Filters.exists("phone")))
9799

@@ -104,6 +106,7 @@ database.createCollection("contacts", CreateCollectionOptions().validationOption
104106
You can get a list of the collections in a database using the [`MongoDatabase.listCollectionNames()`]({{< apiref "mongo-scala-driver" "org/mongodb/scala/MongoDatabase.html#listCollectionNames--" >}}) method:
105107

106108
```scala
109+
// Note: this code example uses a custom implicit helper referenced in the Quick Start Primer
107110
database.listCollectionNames().printResults()
108111
```
109112

@@ -112,6 +115,7 @@ database.listCollectionNames().printResults()
112115
You can drop a collection by using the [`MongoCollection.drop()`]({{< apiref "mongo-scala-driver" "org/mongodb/scala/MongoCollection.html#drop--" >}}) method:
113116

114117
```scala
118+
// Note: this code example uses a custom implicit helper referenced in the Quick Start Primer
115119
val collection: MongoCollection[Document] = database.getCollection("contacts")
116120
collection.drop().printResults()
117121
```
@@ -141,6 +145,8 @@ An overload of the `getCollection` method allows clients to specify a different
141145
users may wish to use the strict and typesafe `BsonDocument` class with the CRUD API:
142146

143147
```scala
148+
// Note: this code example uses a custom implicit helper referenced in the Quick Start Primer
149+
144150
// Pass BsonDocument.class as the second argument
145151
import org.mongodb.scala.bson._
146152

reference/content/driver-scala/tutorials/geospatial-search.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ helper to create a specification for the `2dsphere` index and pass to [`MongoCol
4949
The following example creates a `2dsphere` index on the `"contact.location"` field for the `restaurants` collection.
5050

5151
```scala
52+
// Note: this code example uses a custom implicit helper referenced in the Quick Start Primer
5253
val collection = database.getCollection("restaurants")
5354
collection.createIndex(Indexes.geo2dsphere("contact.location")).printResults()
5455
```
@@ -60,6 +61,7 @@ MongoDB provides various [geospatial query operators]({{<docsref "reference/oper
6061
The following example returns documents that are at least 1000 meters from and at most 5000 meters from the specified GeoJSON point ``org.mongodb.scala.model.geojson.Point``, sorted from nearest to farthest:
6162

6263
```scala
64+
// Note: this code example uses a custom implicit helper referenced in the Quick Start Primer
6365
val refPoint = Point(Position(-73.9667, 40.78))
6466
collection.find(Filters.near("contact.location", refPoint, 5000.0, 1000.0)).printResults()
6567
```

reference/content/driver-scala/tutorials/gridfs.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ If you should need to rename a file, then use the [`rename`]({{< apiref "mongo-s
144144
The following example renames a file to "mongodbTutorial":
145145

146146
```scala
147+
// Note: this code example uses a custom implicit helper referenced in the Quick Start Primer
147148
val fileId: ObjectId = ??? //ObjectId of a file uploaded to GridFS
148149

149150
gridFSBucket.rename(fileId, "mongodbTutorial").printResults()
@@ -162,6 +163,7 @@ To delete a file from the `GridFSBucket` use the [`delete`]({{< apiref "mongo-sc
162163
The following example deletes a file from the `GridFSBucket`:
163164

164165
```scala
166+
// Note: this code example uses a custom implicit helper referenced in the Quick Start Primer
165167
val fileId: ObjectId = ??? //ObjectId of a file uploaded to GridFS
166168

167169
gridFSBucket.delete(fileId).printResults()

reference/content/driver-scala/tutorials/indexes.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ To create a specification for an ascending index, use the [`Indexes.ascending`](
6060
The following example creates an ascending index on the `name` field:
6161

6262
```scala
63+
// Note: this code example uses a custom implicit helper referenced in the Quick Start Primer
6364
collection.createIndex(Indexes.ascending("name"))
6465
.printResults()
6566
```
@@ -70,6 +71,7 @@ The following example creates an ascending [compound index]({{<docsref "core/ind
7071
field:
7172

7273
```scala
74+
// Note: this code example uses a custom implicit helper referenced in the Quick Start Primer
7375
collection.createIndex(Indexes.ascending("stars", "name"))
7476
.printResults()
7577
```
@@ -85,6 +87,7 @@ To create a specification of a descending index, use the [`Indexes.descending`](
8587
The following example creates a descending index on the `stars` field:
8688

8789
```scala
90+
// Note: this code example uses a custom implicit helper referenced in the Quick Start Primer
8891
collection.createIndex(Indexes.descending("stars"))
8992
.printResults()
9093
```
@@ -94,6 +97,7 @@ collection.createIndex(Indexes.descending("stars"))
9497
The following example creates a descending [compound index]({{<docsref "core/index-compound" >}}) on the `stars` field and the `name` field:
9598

9699
```scala
100+
// Note: this code example uses a custom implicit helper referenced in the Quick Start Primer
97101
collection.createIndex(Indexes.descending("stars", "name"))
98102
.printResults()
99103
```
@@ -111,6 +115,7 @@ To create a specification for a compound index where all the keys are ascending,
111115
The following exam 10000 ple creates a compound index with the `stars` field in descending order and the `name` field in ascending order:
112116

113117
```scala
118+
// Note: this code example uses a custom implicit helper referenced in the Quick Start Primer
114119
collection.createIndex(
115120
Indexes.compoundIndex(Indexes.descending("stars"),
116121
Indexes.ascending("name")))
@@ -125,6 +130,7 @@ MongoDB provides [text indexes]({{<docsref "core/index-text" >}}) to support tex
125130
The following example creates a text index on the `name` field:
126131

127132
```scala
133+
// Note: this code example uses a custom implicit helper referenced in the Quick Start Primer
128134
collection.createIndex(Indexes.text("name"))
129135
.printResults()
130136
```
@@ -136,6 +142,7 @@ To create a specification for a [hashed index]({{<docsref "core/index-hashed" >}
136142
The following example creates a hashed index on the `_id` field:
137143

138144
```scala
145+
// Note: this code example uses a custom implicit helper referenced in the Quick Start Primer
139146
collection.createIndex(Indexes.hashed("_id"))
140147
.printResults()
141148
```
@@ -152,6 +159,7 @@ To create a specification for a [`2dsphere` index]({{<docsref "core/2dsphere" >}
152159
The following example creates a `2dsphere` index on the `"contact.location"` field:
153160

154161
```scala
162+
// Note: this code example uses a custom implicit helper referenced in the Quick Start Primer
155163
collection.createIndex(Indexes.geo2dsphere("contact.location"))
156164
.printResults()
157165
```
@@ -172,6 +180,7 @@ The Scala driver provides the [IndexOptions]({{< apiref "mongo-scala-driver" "or
172180
The following specifies a [`unique(true)`]({{< apiref "mongo-scala-driver" "org/mongodb/scala/model/index.html#IndexOptions=com.mongodb.client.model.IndexOptions" >}}) option to create a [unique index]({{<docsref "core/index-unique" >}}) on the `name` and `stars` fields:
173181

174182
```scala
183+
// Note: this code example uses a custom implicit helper referenced in the Quick Start Primer
175184
val indexOptions = IndexOptions().unique(true)
176185
collection.createIndex(Indexes.ascending("name", "stars"), indexOptions)
177186
.printResults()
@@ -186,6 +195,7 @@ To create a [partial index]({{<docsref "core/index-partial/" >}}), include a [pa
186195
The following example creates a partial index on documents that have `status` field equal to `"A"`.
187196

188197
```scala
198+
// Note: this code example uses a custom implicit helper referenced in the Quick Start Primer
189199
val partialFilterIndexOptions = IndexOptions()
190200
.partialFilterExpression(Filters.exists("contact.email"))
191201
collection.createIndex(
@@ -200,6 +210,7 @@ For more information on partial indexes, see [Partial Indexes]({{<docsref "core/
200210
Use the `listIndexes()` method to get a list of indexes. The following lists the indexes on the collection:
201211

202212
```scala
213+
// Note: this code example uses a custom implicit helper referenced in the Quick Start Primer
203214
collection.listIndexes().printResults()
204215
```
205216

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,14 @@ To query the collection, you can use the collection's [`find()`]({{< apiref "mon
5050
You can call the method without any arguments to query all documents in a collection:
5151

5252
```scala
53+
// Note: this code example uses a custom implicit helper referenced in the Quick Start Primer
5354
collection.find().printResults()
5455
```
5556

5657
Or pass a filter to query for documents that match the filter criteria:
5758

5859
```scala
60+
// Note: this code example uses a custom implicit helper referenced in the Quick Start Primer
5961
collection.find(equal("name", "456 Cookies Shop"))
6062
.printResults()
6163
```
@@ -69,13 +71,15 @@ To query for documents that match certain conditions, pass a filter document to
6971
To specify an empty filter (i.e. match all documents in a collection), use an empty [`Document`]({{< apiref "mongo-scala-driver" "org/mongodb/scala/bson/index.html#Document:org.mongodb.scala.bson.collection.immutable.Document.type" >}}) object.
7072

7173
```scala
74+
// Note: this code example uses a custom implicit helper referenced in the Quick Start Primer
7275
collection.find(Document()).printResults()
7376
```
7477
{{% note class="tip"%}}
7578
For the [`find()`]({{< apiref "mongo-scala-driver" "org/mongodb/scala/MongoCollection.html#find[C]()(implicite:org.mongodb.scala.bson.DefaultHelper.DefaultsTo[C,TResult],implicitct:scala.reflect.ClassTag[C]):org.mongodb.scala.FindObservable[C]" >}}) method, you can also call the method without passing a filter object to match all documents in a collection.
7679
{{% /note %}}
7780

7881
```scala
82+
// Note: this code example uses a custom implicit helper referenced in the Quick Start Primer
7983
collection.find().printResults()
8084
```
8185

@@ -90,6 +94,7 @@ Consider the following `find` operation which includes a filter `Document` which
9094
- the `categories` field equals `"Bakery"` (or if `categories` is an array, contains the string `"Bakery"` as an element):
9195

9296
```scala
97+
// Note: this code example uses a custom implicit helper referenced in the Quick Start Primer
9398
collection.find(
9499
Document("stars" -> Document("$gte" -> 2, "$lt"-> 5, "categories" -> "Bakery")))
95100
.printResults()
@@ -98,6 +103,7 @@ collection.find(
98103
The following example specifies the same filter condition using the [`Filters`]({{< apiref "mongo-scala-driver" "org/mongodb/scala/model/Filters$.html" >}}) helper methods:
99104

100105
```scala
106+
// Note: this code example uses a custom implicit helper referenced in the Quick Start Primer
101107
collection.find(and(gte("stars", 2), lt("stars", 5), equal("categories", "Bakery")))
102108
.printResults()
103109
```
@@ -116,6 +122,7 @@ By default, queries in MongoDB return all fields in matching documents. To speci
116122
Consider the following `find` operation which includes a projection `Document` which specifies that the matching documents return only the `name` field, `stars` field, and the `categories` field.
117123

118124
```scala
125+
// Note: this code calls methods from a custom implicit helper referenced in the Quick Start Primer
119126
collection.find(and(gte("stars", 2), lt("stars", 5), equal("categories", "Bakery")))
120127
.projection(Document("name" -> 1, "stars" -> 1, "categories" -> 1, "_id" -> 0))
121128
.printResults()
@@ -125,6 +132,7 @@ To facilitate the creation of projection documents, the Scala driver provides th
125132
[`Projections`]({{< apiref "mongo-scala-driver" "org/mongodb/scala/model/Projections$.html" >}}) class.
126133

127134
```scala
135+
// Note: this code calls methods from a custom implicit helper referenced in the Quick Start Primer
128136
collection.find(and(gte("stars", 2), lt("stars", 5), equal("categories", "Bakery")))
129137
.projection(fields(include("name", "stars", "categories"), excludeId()))
130138
.printResults()
@@ -140,6 +148,7 @@ see the [Text Search tutorial]({{<relref "driver-scala/tutorials/text-search.md"
140148
To sort documents, pass a [sort specification document]({{<docsref "reference/method/cursor.sort/#cursor.sort" >}}) to the [`FindObservable.sort()`]({{< apiref "mongo-scala-driver" "org/mongodb/scala/FindObservable.html#sort(sort:org.mongodb.scala.bson.conversions.Bson):org.mongodb.scala.FindObservable[TResult]" >}}) method. The Scala driver provides [`Sorts`]({{< relref "builders/sorts.md" >}}) helpers to facilitate the sort specification document.
141149

142150
```scala
151+
// Note: this code example uses a custom implicit helper referenced in the Quick Start Primer
143152
collection.find(and(gte("stars", 2), lt("stars", 5), equal("categories", "Bakery")))
144153
.sort(ascending("name"))
145154
.printResults()
@@ -150,6 +159,7 @@ collection.find(and(gte("stars", 2), lt("stars", 5), equal("categories", "Bakery
150159
The [`FindObservable`]({{< apiref "mongo-scala-driver" "org/mongodb/scala/FindObservable.html" >}}) methods themselves return `FindObservable` objects, and as such, you can append multiple `FindObservable` methods to the `find()` method.
151160

152161
```scala
162+
// Note: this code example uses a custom implicit helper referenced in the Quick Start Primer
153163
collection.find(and(gte("stars", 2), lt("stars", 5), equal("categories", "Bakery")))
154164
.sort(ascending("name"))
155165
.projection(fields(include("name", "stars", "categories"), excludeId()))
@@ -163,6 +173,7 @@ To [explain]({{< docsref "reference/command/explain/" >}}) a find operation, cal
163173
method:
164174

165175
```scala
176+
// Note: this code example uses a custom implicit helper referenced in the Quick Start Primer
166177
collection.find(and(gte("stars", 2), lt("stars", 5), eq("categories", "Bakery")))
167178
.explain()
168179
.printResults()

0 commit comments

Comments
 (0)
0