Skip to content

Commit fcc18ef

Browse files
haglrozza
authored andcommitted
Doc: Small fixes in the code examples of quick tour (mongodb#28)
* Scala syntax for type parameter The example used a java-style type parameter and doesn't compile with scala. * example code fixed * Import the main classes for the examples Since it's the quick tour in getting started, I'd find it helpful to provide a import statement for the main classes. * import Sorts, Projections, Aggregates and Updates * fixed group aggregation example
1 parent 6b6fa4d commit fcc18ef

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

docs/reference/content/getting-started/quick-tour.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ The following example shows multiple ways to connect to the database `mydb` on t
2727

2828

2929
```scala
30+
import org.mongodb.scala._
31+
3032
// To directly connect to the default server localhost on port 27017
3133
val mongoClient: MongoClient = MongoClient()
3234

@@ -126,14 +128,14 @@ In the API all methods returning a `Observables` are "cold" streams meaning that
126128
The example below does nothing:
127129

128130
```scala
129-
val observable: Observable<Completed> = collection.insertOne(doc)
131+
val observable: Observable[Completed] = collection.insertOne(doc)
130132
```
131133

132134
Only when an `Observable` is subscribed to and data requested will the operation happen:
133135

134136
```scala
135137
// Explictly subscribe:
136-
observable.insertOne(doc).subscribe(new Observer[Completed] {
138+
observable.subscribe(new Observer[Completed] {
137139

138140
override def onNext(result: Completed): Unit = println("Inserted")
139141

@@ -281,6 +283,8 @@ We add a sort to a find query by calling the `sort()` method on a `FindObservabl
281283
[`descending("i")`]({{< apiref "org.mongodb.scala.model.Sorts$@descending(fieldNames:String*):org.bson.conversions.Bson">}}) helper to sort our documents:
282284

283285
```scala
286+
import org.mongodb.scala.model.Sorts._
287+
284288
collection.find(exists("i")).sort(descending("i")).first().printHeadResult()
285289
```
286290

@@ -291,6 +295,8 @@ helpers can be used to build the projection parameter for the find operation and
291295
Below we'll sort the collection, exclude the `_id` field and output the first matching document:
292296

293297
```scala
298+
import org.mongodb.scala.model.Projections._
299+
294300
collection.find().projection(excludeId()).first().printHeadResult()
295301
```
296302

@@ -306,6 +312,8 @@ in conjunction with the [`$multiply`]({{< docsref "reference/operator/aggregatio
306312
value:
307313

308314
```scala
315+
import org.mongodb.scala.model.Aggregates._
316+
309317
collection.aggregate(Seq(filter(gt("i", 0)),
310318
project(Document("""{ITimes10: {$multiply: ["$i", 10]}}""")))
311319
).printResults()
@@ -318,7 +326,7 @@ For [`$group`]({{< relref "builders/aggregation.md#group" >}}) operations use th
318326
[`Accumulators.sum`]({{< apiref "com/mongodb/client/model/Accumulators#sum-java.lang.String-TExpression-" >}}) helper:
319327

320328
```scala
321-
collection.aggregate(singletonList(group(null, sum("total", "$i")))).first(printDocument);
329+
collection.aggregate(List(group(null, sum("total", "$i")))).printHeadResult()
322330
```
323331

324332
{{% note %}}
@@ -336,6 +344,8 @@ To update at most a single document (may be 0 if none match the filter), use the
336344
method to specify the filter and the update document. Here we update the first document that meets the filter `i` equals `10` and set the value of `i` to `110`:
337345

338346
```scala
347+
import org.mongodb.scala.model.Updates._
348+
339349
collection.updateOne(equal("i", 10), set("i", 110)).printHeadResult("Update Result: ")
340350
```
341351

0 commit comments

Comments
 (0)