Skip to content

Commit 1cd0aaf

Browse files
committed
Docs: updated for 1.1.0-rc0
1 parent 2e5bf15 commit 1cd0aaf

File tree

12 files changed

+128
-19
lines changed

12 files changed

+128
-19
lines changed

docs/landing/data/releases.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ driverName = "mongo-scala-driver"
22
githubRepo = "mongo-scala-driver"
33
current = "1.0.1"
44

5+
[[versions]]
6+
version = "1.1.0-rc0"
7+
docs = "./1.1"
8+
api = "./1.1/scaladoc"
9+
510
[[versions]]
611
version = "1.0.1"
712
status = "current"

docs/landing/static/versions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[{"version": "1.0"}]
1+
[{"version": "1.1"}, {"version": "1.0"}]

docs/reference/config.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
baseurl = "/mongo-scala-driver/1.0"
1+
baseurl = "/mongo-scala-driver/1.1"
22
languageCode = "en-us"
33
title = "MongoDB Scala Driver"
44
theme = "mongodb"

docs/reference/content/builders/aggregation.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ This example simply projects the `qty` field into a new field called `quantity`.
6565
project(computed("quantity", "$qty"))
6666
```
6767

68+
### Sample
69+
The [`$sample`]({{< docsref "reference/operator/aggregation/sample/" >}}) pipeline stage randomly select N documents from its input.
70+
This example creates a pipeline stage that randomly selects 5 documents from the collection:
71+
72+
```scala
73+
sample(5)
74+
```
75+
6876
### Sort
6977

7078
The [`$sort`]({{< docsref "reference/operator/aggregation/sort/" >}}) pipeline stage passes all documents to the next stage,
@@ -101,6 +109,18 @@ This example limits the number of documents to `10`:
101109
limit(10)
102110
```
103111

112+
### Lookup
113+
114+
Starting in 3.2, MongoDB provides a new [`$lookup`]({{< docsref "reference/operator/aggregation/lookup/" >}}) pipeline stage
115+
that performs a left outer join with another collection to filter in documents from the joined collection for processing.
116+
117+
This example performs a left outer join on the `fromCollection` collection, joining the `local` field to the `from` field and outputted in
118+
the `joinedOutput` field:
119+
120+
```scala
121+
lookup("fromCollection", "local", "from", "joinedOutput")
122+
```
123+
104124
### Group
105125

106126
The [`$group`]({{< docsref "reference/operator/aggregation/group/" >}}) pipeline stage groups documents by some specified
@@ -130,6 +150,19 @@ This example outputs, for each document, a document for each element in the `siz
130150
unwind("$sizes")
131151
```
132152

153+
Available with MongoDB 3.2, this example also includes any documents that have missing or `null` values for the `$sizes` field or where
154+
the `$sizes` list is empty:
155+
156+
```scala
157+
unwind("$sizes", UnwindOptions().preserveNullAndEmptyArrays(true))
158+
```
159+
160+
Available with MongoDB 3.2, this example unwinds the `sizes` array and also outputs the array index into the `$position` field:
161+
162+
```scala
163+
unwind("$sizes", UnwindOptions().includeArrayIndex("$position"))
164+
```
165+
133166
### Out
134167

135168
The [`$out`]({{< docsref "reference/operator/aggregation/out/" >}}) pipeline stage outputs all documents to the specified

docs/reference/content/builders/filters.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,39 @@ This example assumes a collection that has a text index in the field `abstract`.
151151
containing the term `coffee`:
152152

153153
```scala
154-
text("abstract", "coffee")
154+
text("coffee")
155+
```
156+
157+
Available with MongoDB 3.2, a version 3 text index allows case-sensitive searches. This example selects documents that have an
158+
`abstract` field containing the exact term `coffee`:
159+
160+
```scala
161+
text("coffee", TextSearchOptions().caseSensitive(true))
162+
```
163+
164+
Available with MongoDB 3.2, a version 3 text index allows diacritic-sensitive searches. This example selects documents that have an
165+
`abstract` field containing the exact term `café`:
166+
167+
```scala
168+
text("café", TextSearchOptions().diacriticSensitive(true))
169+
```
170+
171+
### Bitwise
172+
173+
The bitwise query operators, available with MongoDB 3.2 include:
174+
175+
- `bitsAllSet`: Selects documents where the all the specified bits of a field are set (i.e. 1).
176+
- `bitsAllClear`: Selects documents where the all the specified bits of a field are clear (i.e. 0).
177+
- `bitsAnySet`: Selects documents where at least one of the specified bits of a field are set (i.e. 1).
178+
- `bitsAnyClear`: Selects documents where at least one of the specified bits of a field are clear (i.e. 0)
179+
180+
181+
#### Examples
182+
183+
The example selects documents that have a `bitField` field with bits set at positions of the corresponding bitmask `50` (i.e. `00110010`):
184+
185+
```scala
186+
bitsAllSet("bitField", 50)
155187
```
156188

157189
### Geospatial

docs/reference/content/getting-started/installation-guide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ The recommended way to get started using the driver in your project is with a de
1717
## MongoDB Scala Driver
1818
The MongoDB Scala Driver
1919

20-
{{< install artifactId="mongo-scala-driver" version="1.0.1" mongoDriverVersion="3.1.0" scalaVersion="2.11">}}
20+
{{< install artifactId="mongo-scala-driver" version="1.1.0-rc0" mongoDriverVersion="3.2.0-rc0" scalaVersion="2.11">}}

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ collection.drop().headResult()
9090

9191
MongoDB supports secondary indexes. To create an index, you just
9292
specify the field or combination of fields, and for each field specify the direction of the index for that field.
93-
For `1` ascending or `-1` for descending. The following creates an ascending index on the `i` field by using the
94-
[`Sorts.ascending`]({{< apiref "org.mongodb.scala.model.Sorts$@ascending(fieldNames:String*):org.bson.conversions.Bson">}}) helper:
93+
For `1` ascending or `-1` for descending.
94+
We can use the [`Indexes`]({{< relref "builders/indexes.md">}}) helpers to create index keys:
9595

9696
```scala
9797
collection.createIndex(ascending("i")).printResults("Created an index named: ")
@@ -116,7 +116,8 @@ The example should print the following indexes:
116116

117117
MongoDB also provides text indexes to support text search of string
118118
content. Text indexes can include any field whose value is a string or
119-
an array of string elements.
119+
an array of string elements. To create a text index use the [`Indexes.text`]({{< relref "builders/indexes.md#text-index">}})
120+
static helper:
120121

121122
The following example creates a text index by specifying the string literal "text" in the index document, then insert some sample documents.
122123
Using a for comprehension we can combine the two operations:
@@ -135,14 +136,14 @@ indexAndInsert.results()
135136
```
136137

137138
As of MongoDB 2.6, text indexes are now integrated into the main query
138-
language and enabled by default (here we use the [`Filters.text`]({{< coreapiref "com/mongodb/client/model/Filters.html#text-java.lang.String-">}}) helper):
139+
language and enabled by default (here we use the [`Filters.text`]({{< relref "builders/filters.md#evaluation">}}) helper):
139140

140141
```scala
141142
// Find using the text index
142143
collection.count(text("textual content -irrelevant")).printResults("Text search matches: ")
143144

144145
// Find using the $language operator
145-
val textSearch: Bson = text("textual content -irrelevant", "english")
146+
val textSearch: Bson = text("textual content -irrelevant", TextSearchOptions().language("english"))
146147
collection.count(textSearch).printResults("Text search matches (english): ")
147148

148149
// Find the highest scoring match

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

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,9 @@ will eventually print just one document:
252252
```
253253

254254
{{% note %}}
255-
Use the [Filters]({{< apiref "org.mongodb.scala.model.Filters$">}}), [Sorts]({{< apiref "org.mongodb.scala.model.Sorts$">}}),
256-
[Projections]({{< apiref "org.mongodb.scala.model.Projections$">}}) and [Updates]({{< apiref "org.mongodb.scala.model.Updates$">}})
257-
helpers for simple and concise ways of building up queries and updates
255+
Use the [`Filters`]({{< relref "builders/filters.md">}}), [`Sorts`]({{< relref "builders/sorts.md">}}),
256+
[`Projections`]({{< relref "builders/projections.md">}}) and [`Updates`]({{< relref "builders/updates.md">}})
257+
helpers for simple and concise ways of building up queries.
258258
{{% /note %}}
259259

260260
## Get a Set of Documents with a Query
@@ -294,6 +294,38 @@ Below we'll sort the collection, exclude the `_id` field and output the first ma
294294
collection.find().projection(excludeId()).first().printHeadResult()
295295
```
296296

297+
## Aggregations
298+
299+
Sometimes we need to aggregate the data stored in MongoDB. The [`Aggregates`]({{< relref "builders/aggregation.md" >}}) helper provides
300+
builders for each of type of aggregation stage.
301+
302+
Below we'll do a simple two step transformation that will calculate the value of `i * 10`. First we find all Documents
303+
where `i > 0` by using the [`Aggregates.filter`]({{< relref "builders/aggregation.md#filter" >}})
304+
helper. Then we reshape the document by using [`Aggregates.project`]({{< relref "builders/aggregation.md#project" >}})
305+
in conjunction with the [`$multiply`]({{< docsref "reference/operator/aggregation/multiply/" >}}) operator to calculate the "`ITimes10`"
306+
value:
307+
308+
```scala
309+
collection.aggregate(Seq(filter(gt("i", 0)),
310+
project(Document("""{ITimes10: {$multiply: ["$i", 10]}}""")))
311+
).printResults()
312+
```
313+
314+
For [`$group`]({{< relref "builders/aggregation.md#group" >}}) operations use the
315+
[`Accumulators`]({{< apiref "com/mongodb/client/model/Accumulators" >}}) helper for any
316+
[accumulator operations]({{< docsref "reference/operator/aggregation/group/#accumulator-operator" >}}). Below we sum up all the values of
317+
`i` by using the [`Aggregates.group`]({{< relref "builders/aggregation.md#group" >}}) helper in conjunction with the
318+
[`Accumulators.sum`]({{< apiref "com/mongodb/client/model/Accumulators#sum-java.lang.String-TExpression-" >}}) helper:
319+
320+
```java
321+
collection.aggregate(singletonList(group(null, sum("total", "$i")))).first(printDocument);
322+
```
323+
324+
{{% note %}}
325+
Currently, there are no helpers for [aggregation expressions]({{< docsref "meta/aggregation-quick-reference/#aggregation-expressions" >}}).
326+
Use the [`Document.parse()`]({{< relref "bson/extended-json.md" >}}) helper to quickly build aggregation expressions from extended JSON.
327+
{{% /note %}}
328+
297329
## Updating documents
298330

299331
There are numerous [update operators](http://docs.mongodb.org/manual/reference/operator/update-field/)

docs/reference/data/mongodb.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
githubUser = "mongodb"
22
githubRepo = "mongo-scala-driver"
33
githubBranch = "master"
4-
currentVersion = "1.0"
4+
currentVersion = "1.1"
55
highlightTheme = "idea.css"
66
apiUrl = "/scaladoc/index.html"
7-
coreApiUrl = "http://api.mongodb.org/java/3.1/"
8-
coreDocsUrl = "http://mongodb.github.io/mongo-java-driver/3.1/"
9-
mongoDriverVersion = "3.1.0" # Update in installation-guide.md
7+
coreApiUrl = "http://api.mongodb.org/java/3.2/"
8+
coreDocsUrl = "http://mongodb.github.io/mongo-java-driver/3.2/"
9+
mongoDriverVersion = "3.2.0-rc0" # Update in installation-guide.md

examples/src/test/scala/tour/QuickTour.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package tour
1919
import scala.collection.immutable.IndexedSeq
2020

2121
import org.mongodb.scala._
22+
import org.mongodb.scala.model.Aggregates._
2223
import org.mongodb.scala.model.Filters._
2324
import org.mongodb.scala.model.Projections._
2425
import org.mongodb.scala.model.Sorts._
@@ -88,6 +89,11 @@ object QuickTour {
8889
// Projection
8990
collection.find().projection(excludeId()).first().printHeadResult()
9091

92+
//Aggregation
93+
collection.aggregate(Seq(filter(gt("i", 0)),
94+
project(Document("""{ITimes10: {$multiply: ["$i", 10]}}""")))
95+
).printResults()
96+
9197
// Update One
9298
collection.updateOne(equal("i", 10), set("i", 110)).printHeadResult("Update Result: ")
9399

0 commit comments

Comments
 (0)