Skip to content

Commit 4d91564

Browse files
committed
Merge branch 'v5.4' of github.com:mongodb/docs-kotlin-sync into v5.4
2 parents be52b7f + efbbe28 commit 4d91564

File tree

3 files changed

+76
-4
lines changed

3 files changed

+76
-4
lines changed

source/aggregation.txt

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Transform Your Data with Aggregation
99
:values: reference
1010

1111
.. meta::
12-
:keywords: code example, transform, computed, pipeline
12+
:keywords: code example, transform, computed, pipeline, Atlas Search
1313
:description: Learn how to use the Kotlin Sync driver to perform aggregation operations.
1414

1515
.. contents:: On this page
@@ -80,6 +80,7 @@ The following limitations apply when using aggregation operations:
8080
</reference/operator/aggregation/graphLookup/>` stage has a strict
8181
memory limit of 100 megabytes and ignores the ``allowDiskUse`` option.
8282

83+
8384
Aggregation Example
8485
-------------------
8586

@@ -188,6 +189,50 @@ and adds the ``$explain`` stage to output the operation details:
188189
...
189190
}
190191

192+
.. _kotlin-sync-atlas-search-stage:
193+
194+
Atlas Search
195+
------------
196+
197+
You can perform an :atlas:`Atlas Search </atlas-search>` query by creating and running
198+
an aggregation pipeline that contains one of the following pipeline stages:
199+
200+
- ``$search``
201+
- ``$searchMeta``
202+
203+
To learn more about Atlas Search pipeline stages, see :atlas:`Choose the
204+
Aggregation Pipeline Stage </atlas-search/query-syntax/>` in the Atlas
205+
documentation.
206+
207+
Create a Pipeline Search Stage
208+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
209+
210+
You can create the search criteria in your Atlas Search pipeline stage
211+
by using Search operators.
212+
213+
.. sharedinclude:: dbx/jvm/atlas-search-operator-helpers.rst
214+
215+
.. replacement:: as-idx-link
216+
217+
the :ref:`kotlin-sync-atlas-search-index` guide
218+
219+
.. replacement:: atlas-query-operators-example
220+
221+
.. io-code-block::
222+
223+
.. input:: /includes/aggregation/aggregation.kt
224+
:language: kotlin
225+
:start-after: // start-atlas-searchoperator-helpers
226+
:end-before: // end-atlas-searchoperator-helpers
227+
:dedent:
228+
229+
.. output::
230+
:language: console
231+
:visible: false
232+
233+
Document{{_id=..., genres=[Comedy, Romance], title=Love at First Bite, year=1979}}
234+
Document{{_id=..., genres=[Comedy, Drama], title=Love Affair, year=1994}}
235+
191236
Additional Information
192237
----------------------
193238

@@ -217,4 +262,7 @@ For more information about executing aggregation operations with the {+driver-sh
217262
see the following API documentation:
218263

219264
- `aggregate() <{+driver-api+}/-mongo-collection/aggregate.html>`__
220-
- `AggregateIterable <{+driver-api+}/-aggregate-iterable/index.html>`__
265+
- `AggregateIterable <{+driver-api+}/-aggregate-iterable/index.html>`__
266+
- `Aggregates <{+core-api+}/client/model/Aggregates>`__
267+
- `search() <{+core-api+}/client/model/Aggregates#search(com.mongodb.client.model.search.SearchOperator)>`__
268+
- `project() <{+core-api+}/client/model/Aggregates#project(org.bson.conversions.Bson)>`__

source/includes/aggregation/aggregation.kt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import com.mongodb.client.model.Accumulators
44
import com.mongodb.client.model.Aggregates
55
import com.mongodb.client.model.Filters
66
import com.mongodb.kotlin.client.MongoClient
7+
import com.mongodb.client.model.Projections
8+
import com.mongodb.client.model.search.SearchOperator
9+
import com.mongodb.client.model.search.SearchPath.fieldPath
710
import org.bson.Document
811

912
// start-data-class
@@ -42,5 +45,27 @@ fun main() {
4245
// start-aggregation-explain
4346
print(collection.aggregate(pipeline).explain())
4447
// end-aggregation-explain
48+
49+
// start-atlas-searchoperator-helpers
50+
val searchStage = Aggregates.search(
51+
SearchOperator.compound()
52+
.filter(
53+
listOf(
54+
SearchOperator.`in`(fieldPath("genres"), listOf("Comedy")),
55+
SearchOperator.phrase(fieldPath("fullplot"), "new york"),
56+
SearchOperator.numberRange(fieldPath("year")).gtLt(1950, 2000),
57+
SearchOperator.wildcard(fieldPath("title"), "Love *")
58+
)
59+
)
60+
)
61+
62+
val projectStage = Aggregates.project(
63+
Projections.include("title", "year", "genres"))
64+
65+
val pipeline = listOf(searchStage, projectStage)
66+
val results = collection.aggregate(pipeline)
67+
68+
results.forEach { result -> println(result) }
69+
// end-atlas-searchoperator-helpers
4570
}
4671

source/whats-new.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ and features:
5454

5555
.. replacement:: atlas-query-operators
5656

57-
the `SearchOperator <{+core-api+}/client/model/search/SearchOperator.html>`__
58-
interface API documentation
57+
the :ref:`Atlas Search <kotlin-sync-atlas-search-stage>` section of the Aggregation guide
5958

6059
.. _kotlin-sync-version-5.3:
6160

0 commit comments

Comments
 (0)