From aa84832ca09d4e3b9f3568dabbb3532bfd004036 Mon Sep 17 00:00:00 2001 From: Rachel Mackintosh Date: Thu, 27 Mar 2025 11:21:16 -0400 Subject: [PATCH 01/15] atlas search page --- source/atlas-search.txt | 75 +++++++++++++++++++++++++++++++++++++++++ source/index.txt | 1 + source/whats-new.txt | 3 +- 3 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 source/atlas-search.txt diff --git a/source/atlas-search.txt b/source/atlas-search.txt new file mode 100644 index 00000000..9242e4f1 --- /dev/null +++ b/source/atlas-search.txt @@ -0,0 +1,75 @@ +.. _kotlin-sync-atlas-search: + +============ +Atlas Search +============ + +.. facet:: + :name: genre + :values: reference + +.. meta:: + :keywords: full text, text analyzer, pipeline + :description: Learn about how to use Atlas Search in the {+driver-long+}. + +.. contents:: On this page + :local: + :backlinks: none + :depth: 2 + :class: singlecol + +Overview +-------- + +In this guide, you can learn how to use the {+driver-short+} to +run Atlas Search queries on a collection. Atlas Search enables you to perform +full-text searches on collections hosted on MongoDB Atlas. + +For more information about Atlas Search queries, see the :atlas:`Atlas Search +documentation ` in the Atlas manual. + +Atlas search queries are different than traditional database queries, as they +are intended to meet more general information needs. Where a database query must +follow a strict syntax, search queries can be for simple text matching, but can +also look for similar phrases, number or date ranges, or use regular expressions +or wildcards. They rely on Atlas Search indexes to specify the behavior of the +search and which fields to index. + +For information about setting up indexes, see the :ref:`Atlas Search and Vector +Search Indexes ` page. + +Building Queries +---------------- + +Atlas Search queries take the form of an aggregation pipeline stage. Atlas +Search provides ``$search`` and ``$searchMeta`` stages, both of which must be the first +stage in any query pipeline + +For more information about pipelines in the {+driver-short+}, see the :ref:`kotlin-sync-aggregation` +page. + +For more information about Atlas pipeline stages, see the :atlas:`Choose the +Aggregation Pipeline Stage `__ page in the Atlas +manual. + +.. sharedinclude:: dbx/jvm/atlas-search-operator-helpers.rst + + .. replacement:: atlas-query-operators-example + + .. code-block:: kotlin + + Bson searchStageFilters = Aggregates.search( + SearchOperator.compound() + .filter( + List.of( + SearchOperator.text(fieldPath("genres"), "Drama"), + SearchOperator.phrase(fieldPath("cast"), "sylvester stallone"), + SearchOperator.numberRange(fieldPath("year")).gtLt(1980, 1989), + SearchOperator.wildcard(fieldPath("title"),"Rocky *") + ))); + + .. replacement:: searchoperator-interface-api-docs + + the `SearchOperator Interface API documentation <{+core-api+}/com/mongodb/client/model/search/SearchOperator.html>`__ + + diff --git a/source/index.txt b/source/index.txt index 5ef09f94..8a229d70 100644 --- a/source/index.txt +++ b/source/index.txt @@ -23,6 +23,7 @@ Specialized Data Formats Builders Run a Command + Atlas Search Monitoring Security In-Use Encryption diff --git a/source/whats-new.txt b/source/whats-new.txt index 63fb0a15..f725d628 100644 --- a/source/whats-new.txt +++ b/source/whats-new.txt @@ -44,8 +44,7 @@ and features: .. replacement:: atlas-query-operators - the `SearchOperator <{+core-api+}/client/model/search/SearchOperator.html>`__ - interface API documentation + the :ref:`Atlas Search ` .. _kotlin-sync-version-5.3: From e5bcf3996c794004c3f5f1bedae0bcc8fd725ec6 Mon Sep 17 00:00:00 2001 From: Rachel Mackintosh Date: Thu, 27 Mar 2025 12:13:09 -0400 Subject: [PATCH 02/15] aggregation section --- source/aggregation.txt | 33 +++++++++++++++++- source/atlas-search.txt | 75 ----------------------------------------- source/index.txt | 1 - source/whats-new.txt | 3 +- 4 files changed, 34 insertions(+), 78 deletions(-) delete mode 100644 source/atlas-search.txt diff --git a/source/aggregation.txt b/source/aggregation.txt index 79d11014..d406a1bc 100644 --- a/source/aggregation.txt +++ b/source/aggregation.txt @@ -9,7 +9,7 @@ Transform Your Data with Aggregation :values: reference .. meta:: - :keywords: code example, transform, computed, pipeline + :keywords: code example, transform, computed, pipeline, Atlas Search :description: Learn how to use the Kotlin Sync driver to perform aggregation operations. .. contents:: On this page @@ -80,6 +80,37 @@ The following limitations apply when using aggregation operations: ` stage has a strict memory limit of 100 megabytes and ignores the ``allowDiskUse`` option. +.. _kotlin-sync-atlas-search-stage: + +Building Pipelines Stages for Atlas Search +------------------------------------------ + +Atlas Search queries take the form of an aggregation pipeline stage. Atlas +Search provides ``$search`` and ``$searchMeta`` stages, both of which must be the first +stage in any query pipeline. For more information about Atlas pipeline stages, see the :atlas:`Choose the +Aggregation Pipeline Stage `__ page in the Atlas +manual. + +.. sharedinclude:: dbx/jvm/atlas-search-operator-helpers.rst + + .. replacement:: atlas-query-operators-example + + .. code-block:: kotlin + + Bson searchStageFilters = Aggregates.search( + SearchOperator.compound() + .filter( + List.of( + SearchOperator.text(fieldPath("genres"), "Drama"), + SearchOperator.phrase(fieldPath("cast"), "sylvester stallone"), + SearchOperator.numberRange(fieldPath("year")).gtLt(1980, 1989), + SearchOperator.wildcard(fieldPath("title"),"Rocky *") + ))); + + .. replacement:: searchoperator-interface-api-docs + + the `SearchOperator Interface API documentation <{+core-api+}/com/mongodb/client/model/search/SearchOperator.html>`__ + Aggregation Example ------------------- diff --git a/source/atlas-search.txt b/source/atlas-search.txt deleted file mode 100644 index 9242e4f1..00000000 --- a/source/atlas-search.txt +++ /dev/null @@ -1,75 +0,0 @@ -.. _kotlin-sync-atlas-search: - -============ -Atlas Search -============ - -.. facet:: - :name: genre - :values: reference - -.. meta:: - :keywords: full text, text analyzer, pipeline - :description: Learn about how to use Atlas Search in the {+driver-long+}. - -.. contents:: On this page - :local: - :backlinks: none - :depth: 2 - :class: singlecol - -Overview --------- - -In this guide, you can learn how to use the {+driver-short+} to -run Atlas Search queries on a collection. Atlas Search enables you to perform -full-text searches on collections hosted on MongoDB Atlas. - -For more information about Atlas Search queries, see the :atlas:`Atlas Search -documentation ` in the Atlas manual. - -Atlas search queries are different than traditional database queries, as they -are intended to meet more general information needs. Where a database query must -follow a strict syntax, search queries can be for simple text matching, but can -also look for similar phrases, number or date ranges, or use regular expressions -or wildcards. They rely on Atlas Search indexes to specify the behavior of the -search and which fields to index. - -For information about setting up indexes, see the :ref:`Atlas Search and Vector -Search Indexes ` page. - -Building Queries ----------------- - -Atlas Search queries take the form of an aggregation pipeline stage. Atlas -Search provides ``$search`` and ``$searchMeta`` stages, both of which must be the first -stage in any query pipeline - -For more information about pipelines in the {+driver-short+}, see the :ref:`kotlin-sync-aggregation` -page. - -For more information about Atlas pipeline stages, see the :atlas:`Choose the -Aggregation Pipeline Stage `__ page in the Atlas -manual. - -.. sharedinclude:: dbx/jvm/atlas-search-operator-helpers.rst - - .. replacement:: atlas-query-operators-example - - .. code-block:: kotlin - - Bson searchStageFilters = Aggregates.search( - SearchOperator.compound() - .filter( - List.of( - SearchOperator.text(fieldPath("genres"), "Drama"), - SearchOperator.phrase(fieldPath("cast"), "sylvester stallone"), - SearchOperator.numberRange(fieldPath("year")).gtLt(1980, 1989), - SearchOperator.wildcard(fieldPath("title"),"Rocky *") - ))); - - .. replacement:: searchoperator-interface-api-docs - - the `SearchOperator Interface API documentation <{+core-api+}/com/mongodb/client/model/search/SearchOperator.html>`__ - - diff --git a/source/index.txt b/source/index.txt index 8a229d70..5ef09f94 100644 --- a/source/index.txt +++ b/source/index.txt @@ -23,7 +23,6 @@ Specialized Data Formats Builders Run a Command - Atlas Search Monitoring Security In-Use Encryption diff --git a/source/whats-new.txt b/source/whats-new.txt index f725d628..56305006 100644 --- a/source/whats-new.txt +++ b/source/whats-new.txt @@ -44,7 +44,8 @@ and features: .. replacement:: atlas-query-operators - the :ref:`Atlas Search ` + the :ref:`Pipeline Stages for Atlas Search + ` section .. _kotlin-sync-version-5.3: From 520d9ec25deee2b9b44cbc54b5c0f0ed69c15354 Mon Sep 17 00:00:00 2001 From: Rachel Mackintosh Date: Thu, 27 Mar 2025 15:29:01 -0400 Subject: [PATCH 03/15] link --- source/aggregation.txt | 6 +++--- source/whats-new.txt | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/source/aggregation.txt b/source/aggregation.txt index d406a1bc..b0bfcee7 100644 --- a/source/aggregation.txt +++ b/source/aggregation.txt @@ -82,10 +82,10 @@ The following limitations apply when using aggregation operations: .. _kotlin-sync-atlas-search-stage: -Building Pipelines Stages for Atlas Search ------------------------------------------- +Pipelines Stages for Atlas Search +--------------------------------- -Atlas Search queries take the form of an aggregation pipeline stage. Atlas +:atlas:`Atlas Search ` queries take the form of an aggregation pipeline stage. Atlas Search provides ``$search`` and ``$searchMeta`` stages, both of which must be the first stage in any query pipeline. For more information about Atlas pipeline stages, see the :atlas:`Choose the Aggregation Pipeline Stage `__ page in the Atlas diff --git a/source/whats-new.txt b/source/whats-new.txt index 56305006..cc3b29b5 100644 --- a/source/whats-new.txt +++ b/source/whats-new.txt @@ -44,7 +44,7 @@ and features: .. replacement:: atlas-query-operators - the :ref:`Pipeline Stages for Atlas Search + the :ref:`Pipelines Stages for Atlas Search ` section .. _kotlin-sync-version-5.3: From 51c8a6634d73d3385ab37eb1de4f7ccf0cc5a692 Mon Sep 17 00:00:00 2001 From: Rachel Mackintosh Date: Thu, 27 Mar 2025 15:31:29 -0400 Subject: [PATCH 04/15] fix link --- source/aggregation.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source/aggregation.txt b/source/aggregation.txt index b0bfcee7..0fbb56c5 100644 --- a/source/aggregation.txt +++ b/source/aggregation.txt @@ -87,8 +87,9 @@ Pipelines Stages for Atlas Search :atlas:`Atlas Search ` queries take the form of an aggregation pipeline stage. Atlas Search provides ``$search`` and ``$searchMeta`` stages, both of which must be the first -stage in any query pipeline. For more information about Atlas pipeline stages, see the :atlas:`Choose the -Aggregation Pipeline Stage `__ page in the Atlas +stage in any query pipeline. For more information about Atlas pipeline stages, +see the :atlas:`Choose the Aggregation Pipeline Stage +` page in the Atlas manual. .. sharedinclude:: dbx/jvm/atlas-search-operator-helpers.rst From df1d30d2e9e60dc40a2b24d847a2e863d7f3c8f6 Mon Sep 17 00:00:00 2001 From: Rachel Mackintosh Date: Thu, 27 Mar 2025 15:35:54 -0400 Subject: [PATCH 05/15] eg search stage --- source/aggregation.txt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/source/aggregation.txt b/source/aggregation.txt index 0fbb56c5..f622680e 100644 --- a/source/aggregation.txt +++ b/source/aggregation.txt @@ -98,15 +98,17 @@ manual. .. code-block:: kotlin - Bson searchStageFilters = Aggregates.search( + val searchStage: Bson = Aggregates.search( SearchOperator.compound() .filter( - List.of( + listOf( SearchOperator.text(fieldPath("genres"), "Drama"), SearchOperator.phrase(fieldPath("cast"), "sylvester stallone"), SearchOperator.numberRange(fieldPath("year")).gtLt(1980, 1989), - SearchOperator.wildcard(fieldPath("title"),"Rocky *") - ))); + SearchOperator.wildcard(fieldPath("title"), "Rocky *") + ) + ) + ) .. replacement:: searchoperator-interface-api-docs From 0ea55ce784e0dc85a219f75674451fd8bc9ee36e Mon Sep 17 00:00:00 2001 From: Rachel Mackintosh Date: Thu, 27 Mar 2025 16:15:32 -0400 Subject: [PATCH 06/15] fix core-api usage --- source/aggregation.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/aggregation.txt b/source/aggregation.txt index f622680e..bf13bd47 100644 --- a/source/aggregation.txt +++ b/source/aggregation.txt @@ -112,7 +112,7 @@ manual. .. replacement:: searchoperator-interface-api-docs - the `SearchOperator Interface API documentation <{+core-api+}/com/mongodb/client/model/search/SearchOperator.html>`__ + the `SearchOperator Interface API documentation <{+core-api+}/client/model/search/SearchOperator.html>`__ Aggregation Example ------------------- From 223840cb2fd585fa3643ba1b60a333bcedea0ae2 Mon Sep 17 00:00:00 2001 From: Rachel Mackintosh Date: Fri, 28 Mar 2025 13:20:24 -0400 Subject: [PATCH 07/15] RR review --- source/aggregation.txt | 90 ++++++++++++++++++++++++++---------------- source/whats-new.txt | 2 +- 2 files changed, 58 insertions(+), 34 deletions(-) diff --git a/source/aggregation.txt b/source/aggregation.txt index bf13bd47..b2d5edaf 100644 --- a/source/aggregation.txt +++ b/source/aggregation.txt @@ -80,39 +80,6 @@ The following limitations apply when using aggregation operations: ` stage has a strict memory limit of 100 megabytes and ignores the ``allowDiskUse`` option. -.. _kotlin-sync-atlas-search-stage: - -Pipelines Stages for Atlas Search ---------------------------------- - -:atlas:`Atlas Search ` queries take the form of an aggregation pipeline stage. Atlas -Search provides ``$search`` and ``$searchMeta`` stages, both of which must be the first -stage in any query pipeline. For more information about Atlas pipeline stages, -see the :atlas:`Choose the Aggregation Pipeline Stage -` page in the Atlas -manual. - -.. sharedinclude:: dbx/jvm/atlas-search-operator-helpers.rst - - .. replacement:: atlas-query-operators-example - - .. code-block:: kotlin - - val searchStage: Bson = Aggregates.search( - SearchOperator.compound() - .filter( - listOf( - SearchOperator.text(fieldPath("genres"), "Drama"), - SearchOperator.phrase(fieldPath("cast"), "sylvester stallone"), - SearchOperator.numberRange(fieldPath("year")).gtLt(1980, 1989), - SearchOperator.wildcard(fieldPath("title"), "Rocky *") - ) - ) - ) - - .. replacement:: searchoperator-interface-api-docs - - the `SearchOperator Interface API documentation <{+core-api+}/client/model/search/SearchOperator.html>`__ Aggregation Example ------------------- @@ -222,6 +189,63 @@ and adds the ``$explain`` stage to output the operation details: ... } +.. _kotlin-sync-atlas-search-stage: + +Atlas Search +------------ + +You can perform an :atlas:`Atlas Search ` query by creating an aggregation pipeline +that contains one of the following pipeline stages: + +- ``$search`` +- ``$searchMeta`` + +For more information about Atlas pipeline stages, see the :atlas:`Choose the +Aggregation Pipeline Stage ` page in the Atlas +documentation. + +Create a Pipeline Search Stage +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can build a Atlas Search pipeline stage using search operators. + +.. sharedinclude:: dbx/jvm/atlas-search-operator-helpers.rst + + .. replacement:: atlas-query-operators-example + + .. io-code-block:: + + .. input:: + :language: kotlin + + val searchStage: Bson = Aggregates.search( + SearchOperator.compound() + .filter( + listOf( + SearchOperator.text(fieldPath("genres"), "Drama"), + SearchOperator.phrase(fieldPath("cast"), "sylvester stallone"), + SearchOperator.numberRange(fieldPath("year")).gtLt(1980, 1989), + SearchOperator.wildcard(fieldPath("title"), "Rocky *") + ) + ) + ) + + val aggregatePipelineStages: List = listOf(searchStage, Aggregates.project(projection)) + val results = collection.aggregate(aggregatePipelineStages) + + results.forEach { result -> println(result) } + + .. output:: + :language: console + :visible: false + + Document{{_id=573a1397f29313caabce86db, genres=[Drama, Sport], cast=[Sylvester Stallone, Talia Shire, Burt Young, Carl Weathers], title=Rocky III, year=1982}} + Document{{_id=573a1398f29313caabce9af0, genres=[Drama, Sport], cast=[Sylvester Stallone, Talia Shire, Burt Young, Carl Weathers], title=Rocky IV, year=1985}} + + .. replacement:: searchoperator-interface-api-docs + + the `SearchOperator Interface API documentation <{+core-api+}/client/model/search/SearchOperator.html>`__ + Additional Information ---------------------- diff --git a/source/whats-new.txt b/source/whats-new.txt index cc3b29b5..dc42b19d 100644 --- a/source/whats-new.txt +++ b/source/whats-new.txt @@ -45,7 +45,7 @@ and features: .. replacement:: atlas-query-operators the :ref:`Pipelines Stages for Atlas Search - ` section + ` section of the Aggregation guide .. _kotlin-sync-version-5.3: From dcdd743191704205c7c18f8f46782797b6384d87 Mon Sep 17 00:00:00 2001 From: Rachel Mackintosh Date: Fri, 28 Mar 2025 13:30:39 -0400 Subject: [PATCH 08/15] add projection --- source/aggregation.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/source/aggregation.txt b/source/aggregation.txt index b2d5edaf..148c129b 100644 --- a/source/aggregation.txt +++ b/source/aggregation.txt @@ -230,6 +230,10 @@ You can build a Atlas Search pipeline stage using search operators. ) ) + val projection = Projections.fields( + Projections.include("title", "year", "genres", "cast") + ) + val aggregatePipelineStages: List = listOf(searchStage, Aggregates.project(projection)) val results = collection.aggregate(aggregatePipelineStages) From d0b3027333edc5f2013474052eff21882d1af48e Mon Sep 17 00:00:00 2001 From: Rachel Mackintosh Date: Fri, 28 Mar 2025 22:50:07 -0400 Subject: [PATCH 09/15] format --- source/aggregation.txt | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/source/aggregation.txt b/source/aggregation.txt index 148c129b..7e4b049b 100644 --- a/source/aggregation.txt +++ b/source/aggregation.txt @@ -218,26 +218,26 @@ You can build a Atlas Search pipeline stage using search operators. .. input:: :language: kotlin - val searchStage: Bson = Aggregates.search( - SearchOperator.compound() - .filter( - listOf( - SearchOperator.text(fieldPath("genres"), "Drama"), - SearchOperator.phrase(fieldPath("cast"), "sylvester stallone"), - SearchOperator.numberRange(fieldPath("year")).gtLt(1980, 1989), - SearchOperator.wildcard(fieldPath("title"), "Rocky *") - ) + val searchStage: Bson = Aggregates.search( + SearchOperator.compound() + .filter( + listOf( + SearchOperator.text(fieldPath("genres"), "Drama"), + SearchOperator.phrase(fieldPath("cast"), "sylvester stallone"), + SearchOperator.numberRange(fieldPath("year")).gtLt(1980, 1989), + SearchOperator.wildcard(fieldPath("title"), "Rocky *") ) - ) + ) + ) - val projection = Projections.fields( - Projections.include("title", "year", "genres", "cast") - ) + val projection = Projections.fields( + Projections.include("title", "year", "genres", "cast") + ) - val aggregatePipelineStages: List = listOf(searchStage, Aggregates.project(projection)) - val results = collection.aggregate(aggregatePipelineStages) - - results.forEach { result -> println(result) } + val aggregatePipelineStages: List = listOf(searchStage, Aggregates.project(projection)) + val results = collection.aggregate(aggregatePipelineStages) + + results.forEach { result -> println(result) } .. output:: :language: console From 29befdb95c2af53cb068661bb580b2fe2bff9007 Mon Sep 17 00:00:00 2001 From: Rachel Mackintosh Date: Fri, 28 Mar 2025 23:24:55 -0400 Subject: [PATCH 10/15] eg --- source/aggregation.txt | 26 ++++------------------ source/includes/aggregation/aggregation.kt | 23 +++++++++++++++++++ 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/source/aggregation.txt b/source/aggregation.txt index 7e4b049b..69e0217f 100644 --- a/source/aggregation.txt +++ b/source/aggregation.txt @@ -215,29 +215,11 @@ You can build a Atlas Search pipeline stage using search operators. .. io-code-block:: - .. input:: + .. input:: /includes/aggregation/aggregation.kt :language: kotlin - - val searchStage: Bson = Aggregates.search( - SearchOperator.compound() - .filter( - listOf( - SearchOperator.text(fieldPath("genres"), "Drama"), - SearchOperator.phrase(fieldPath("cast"), "sylvester stallone"), - SearchOperator.numberRange(fieldPath("year")).gtLt(1980, 1989), - SearchOperator.wildcard(fieldPath("title"), "Rocky *") - ) - ) - ) - - val projection = Projections.fields( - Projections.include("title", "year", "genres", "cast") - ) - - val aggregatePipelineStages: List = listOf(searchStage, Aggregates.project(projection)) - val results = collection.aggregate(aggregatePipelineStages) - - results.forEach { result -> println(result) } + :start-after: // start-atlas-searchoperator-helpers + :end-before: // end-atlas-searchoperator-helpers + :dedent: .. output:: :language: console diff --git a/source/includes/aggregation/aggregation.kt b/source/includes/aggregation/aggregation.kt index 4b675947..2cc4bea9 100644 --- a/source/includes/aggregation/aggregation.kt +++ b/source/includes/aggregation/aggregation.kt @@ -42,5 +42,28 @@ fun main() { // start-aggregation-explain print(collection.aggregate(pipeline).explain()) // end-aggregation-explain + + // start-atlas-searchoperator-helpers + val searchStage: Bson = Aggregates.search( + SearchOperator.compound() + .filter( + listOf( + SearchOperator.text(fieldPath("genres"), "Drama"), + SearchOperator.phrase(fieldPath("cast"), "sylvester stallone"), + SearchOperator.numberRange(fieldPath("year")).gtLt(1980, 1989), + SearchOperator.wildcard(fieldPath("title"), "Rocky *") + ) + ) + ) + + val projection = Projections.fields( + Projections.include("title", "year", "genres", "cast") + ) + + val aggregatePipelineStages: List = listOf(searchStage, Aggregates.project(projection)) + val results = collection.aggregate(aggregatePipelineStages) + + results.forEach { result -> println(result) } + // end-atlas-searchoperator-helpers } From d13b106aa66f9ec87e0a77b2d19f4c46a8f5bf6b Mon Sep 17 00:00:00 2001 From: Rea Rustagi <85902999+rustagir@users.noreply.github.com> Date: Tue, 1 Apr 2025 10:22:16 -0400 Subject: [PATCH 11/15] wip --- source/aggregation.txt | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/source/aggregation.txt b/source/aggregation.txt index 69e0217f..a7878c87 100644 --- a/source/aggregation.txt +++ b/source/aggregation.txt @@ -194,20 +194,21 @@ and adds the ``$explain`` stage to output the operation details: Atlas Search ------------ -You can perform an :atlas:`Atlas Search ` query by creating an aggregation pipeline -that contains one of the following pipeline stages: +You can perform an :atlas:`Atlas Search ` query by creating and running +an aggregation pipeline that contains one of the following pipeline stages: - ``$search`` - ``$searchMeta`` -For more information about Atlas pipeline stages, see the :atlas:`Choose the -Aggregation Pipeline Stage ` page in the Atlas +To learn more about Atlas Search pipeline stages, see :atlas:`Choose the +Aggregation Pipeline Stage ` in the Atlas documentation. Create a Pipeline Search Stage ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -You can build a Atlas Search pipeline stage using search operators. +You can create the search criteria in your Atlas Search pipeline stage +by using Search operators. .. sharedinclude:: dbx/jvm/atlas-search-operator-helpers.rst @@ -228,10 +229,6 @@ You can build a Atlas Search pipeline stage using search operators. Document{{_id=573a1397f29313caabce86db, genres=[Drama, Sport], cast=[Sylvester Stallone, Talia Shire, Burt Young, Carl Weathers], title=Rocky III, year=1982}} Document{{_id=573a1398f29313caabce9af0, genres=[Drama, Sport], cast=[Sylvester Stallone, Talia Shire, Burt Young, Carl Weathers], title=Rocky IV, year=1985}} - .. replacement:: searchoperator-interface-api-docs - - the `SearchOperator Interface API documentation <{+core-api+}/client/model/search/SearchOperator.html>`__ - Additional Information ---------------------- @@ -261,4 +258,4 @@ For more information about executing aggregation operations with the {+driver-sh see the following API documentation: - `aggregate() <{+driver-api+}/-mongo-collection/aggregate.html>`__ -- `AggregateIterable <{+driver-api+}/-aggregate-iterable/index.html>`__ \ No newline at end of file +- `AggregateIterable <{+driver-api+}/-aggregate-iterable/index.html>`__ From 619f989f1ae6029ec648df12af802903e53dbfe4 Mon Sep 17 00:00:00 2001 From: Rea Rustagi <85902999+rustagir@users.noreply.github.com> Date: Tue, 1 Apr 2025 10:33:25 -0400 Subject: [PATCH 12/15] wip --- source/includes/aggregation/aggregation.kt | 30 ++++++++++++---------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/source/includes/aggregation/aggregation.kt b/source/includes/aggregation/aggregation.kt index 2cc4bea9..17bbc588 100644 --- a/source/includes/aggregation/aggregation.kt +++ b/source/includes/aggregation/aggregation.kt @@ -4,6 +4,9 @@ import com.mongodb.client.model.Accumulators import com.mongodb.client.model.Aggregates import com.mongodb.client.model.Filters import com.mongodb.kotlin.client.MongoClient +import com.mongodb.client.model.Projections +import com.mongodb.client.model.search.SearchOperator +import com.mongodb.client.model.search.SearchPath.fieldPath import org.bson.Document // start-data-class @@ -44,25 +47,24 @@ fun main() { // end-aggregation-explain // start-atlas-searchoperator-helpers - val searchStage: Bson = Aggregates.search( - SearchOperator.compound() - .filter( + val searchStage = Aggregates.search( + SearchOperator.compound() + .filter( listOf( - SearchOperator.text(fieldPath("genres"), "Drama"), - SearchOperator.phrase(fieldPath("cast"), "sylvester stallone"), - SearchOperator.numberRange(fieldPath("year")).gtLt(1980, 1989), - SearchOperator.wildcard(fieldPath("title"), "Rocky *") - ) + SearchOperator.text(fieldPath("genres"), "Drama"), + SearchOperator.phrase(fieldPath("cast"), "sylvester stallone"), + SearchOperator.numberRange(fieldPath("year")).gtLt(1980, 1989), + SearchOperator.wildcard(fieldPath("title"), "Rocky *") ) + ) ) - val projection = Projections.fields( - Projections.include("title", "year", "genres", "cast") - ) + val projectStage = Aggregates.project( + Projections.include("title", "year", "genres", "cast")) + + val aggregatePipelineStages = listOf(searchStage, projectStage) + val results = collection.aggregate(aggregatePipelineStages) - val aggregatePipelineStages: List = listOf(searchStage, Aggregates.project(projection)) - val results = collection.aggregate(aggregatePipelineStages) - results.forEach { result -> println(result) } // end-atlas-searchoperator-helpers } From 2866c79650099866f57bfa5c749873cd0914fdbc Mon Sep 17 00:00:00 2001 From: Rea Rustagi <85902999+rustagir@users.noreply.github.com> Date: Tue, 1 Apr 2025 10:37:07 -0400 Subject: [PATCH 13/15] wip --- source/aggregation.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/source/aggregation.txt b/source/aggregation.txt index a7878c87..1a7b9a86 100644 --- a/source/aggregation.txt +++ b/source/aggregation.txt @@ -212,6 +212,10 @@ by using Search operators. .. sharedinclude:: dbx/jvm/atlas-search-operator-helpers.rst + .. replacement:: as-idx-link + + the :ref:`kotlin-sync-atlas-search-index` guide + .. replacement:: atlas-query-operators-example .. io-code-block:: From 091eec4c32e707a4e55eb73cb0db351edcf73507 Mon Sep 17 00:00:00 2001 From: rustagir Date: Tue, 1 Apr 2025 15:41:07 -0400 Subject: [PATCH 14/15] WIP --- source/aggregation.txt | 7 +++++-- source/includes/aggregation/aggregation.kt | 14 +++++++------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/source/aggregation.txt b/source/aggregation.txt index 1a7b9a86..34592cf2 100644 --- a/source/aggregation.txt +++ b/source/aggregation.txt @@ -230,8 +230,8 @@ by using Search operators. :language: console :visible: false - Document{{_id=573a1397f29313caabce86db, genres=[Drama, Sport], cast=[Sylvester Stallone, Talia Shire, Burt Young, Carl Weathers], title=Rocky III, year=1982}} - Document{{_id=573a1398f29313caabce9af0, genres=[Drama, Sport], cast=[Sylvester Stallone, Talia Shire, Burt Young, Carl Weathers], title=Rocky IV, year=1985}} + Document{{_id=..., genres=[Comedy, Romance], title=Love at First Bite, year=1979}} + Document{{_id=..., genres=[Comedy, Drama], title=Love Affair, year=1994}} Additional Information ---------------------- @@ -263,3 +263,6 @@ see the following API documentation: - `aggregate() <{+driver-api+}/-mongo-collection/aggregate.html>`__ - `AggregateIterable <{+driver-api+}/-aggregate-iterable/index.html>`__ +- `Aggregates <{+core-api+}/client/model/Aggregates>`__ +- `search() <{+core-api+}/client/model/Aggregates#search(com.mongodb.client.model.search.SearchOperator)>`__ +- `project() <{+core-api+}/client/model/Aggregates#project(org.bson.conversions.Bson)>`__ diff --git a/source/includes/aggregation/aggregation.kt b/source/includes/aggregation/aggregation.kt index 17bbc588..a804b46e 100644 --- a/source/includes/aggregation/aggregation.kt +++ b/source/includes/aggregation/aggregation.kt @@ -51,19 +51,19 @@ fun main() { SearchOperator.compound() .filter( listOf( - SearchOperator.text(fieldPath("genres"), "Drama"), - SearchOperator.phrase(fieldPath("cast"), "sylvester stallone"), - SearchOperator.numberRange(fieldPath("year")).gtLt(1980, 1989), - SearchOperator.wildcard(fieldPath("title"), "Rocky *") + SearchOperator.`in`(fieldPath("genres"), listOf("Comedy")), + SearchOperator.phrase(fieldPath("fullplot"), "new york"), + SearchOperator.numberRange(fieldPath("year")).gtLt(1950, 2000), + SearchOperator.wildcard(fieldPath("title"), "Love *") ) ) ) val projectStage = Aggregates.project( - Projections.include("title", "year", "genres", "cast")) + Projections.include("title", "year", "genres")) - val aggregatePipelineStages = listOf(searchStage, projectStage) - val results = collection.aggregate(aggregatePipelineStages) + val pipeline = listOf(searchStage, projectStage) + val results = collection.aggregate(pipeline) results.forEach { result -> println(result) } // end-atlas-searchoperator-helpers From 32f617c1f235000c93764a1e74b921a298e6551d Mon Sep 17 00:00:00 2001 From: Rea Rustagi <85902999+rustagir@users.noreply.github.com> Date: Tue, 1 Apr 2025 15:50:20 -0400 Subject: [PATCH 15/15] Update whats-new.txt --- source/whats-new.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/source/whats-new.txt b/source/whats-new.txt index 35b87d17..c237a58b 100644 --- a/source/whats-new.txt +++ b/source/whats-new.txt @@ -50,8 +50,7 @@ and features: .. replacement:: atlas-query-operators - the :ref:`Pipelines Stages for Atlas Search - ` section of the Aggregation guide + the :ref:`Atlas Search ` section of the Aggregation guide .. _kotlin-sync-version-5.3: