Skip to content
This repository was archived by the owner on Jul 16, 2024. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions docs/reference/content/getting-started/quick-tour.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ The following example shows multiple ways to connect to the database `mydb` on t


```scala
import org.mongodb.scala._

// To directly connect to the default server localhost on port 27017
val mongoClient: MongoClient = MongoClient()

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

```scala
val observable: Observable<Completed> = collection.insertOne(doc)
val observable: Observable[Completed] = collection.insertOne(doc)
```

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

```scala
// Explictly subscribe:
observable.insertOne(doc).subscribe(new Observer[Completed] {
observable.subscribe(new Observer[Completed] {

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

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

```scala
import org.mongodb.scala.model.Sorts._

collection.find(exists("i")).sort(descending("i")).first().printHeadResult()
```

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

```scala
import org.mongodb.scala.model.Projections._

collection.find().projection(excludeId()).first().printHeadResult()
```

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

```scala
import org.mongodb.scala.model.Aggregates._

collection.aggregate(Seq(filter(gt("i", 0)),
project(Document("""{ITimes10: {$multiply: ["$i", 10]}}""")))
).printResults()
Expand All @@ -318,7 +326,7 @@ For [`$group`]({{< relref "builders/aggregation.md#group" >}}) operations use th
[`Accumulators.sum`]({{< apiref "com/mongodb/client/model/Accumulators#sum-java.lang.String-TExpression-" >}}) helper:

```scala
collection.aggregate(singletonList(group(null, sum("total", "$i")))).first(printDocument);
collection.aggregate(List(group(null, sum("total", "$i")))).printHeadResult()
```

{{% note %}}
Expand All @@ -336,6 +344,8 @@ To update at most a single document (may be 0 if none match the filter), use the
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`:

```scala
import org.mongodb.scala.model.Updates._

collection.updateOne(equal("i", 10), set("i", 110)).printHeadResult("Update Result: ")
```

Expand Down