From ee4766763f6626a46275598a8d002cd084d2ce73 Mon Sep 17 00:00:00 2001 From: Angela Date: Thu, 13 Mar 2025 16:16:00 -0400 Subject: [PATCH 01/20] make atlas page --- source/atlas-search.txt | 114 ++++++++++++++++++++++++++++++++++++++++ source/index.txt | 1 + 2 files changed, 115 insertions(+) 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..b282874b --- /dev/null +++ b/source/atlas-search.txt @@ -0,0 +1,114 @@ +.. _pymongo-atlas-search: + +============ +Atlas Search +============ + +.. contents:: On this page + :local: + :backlinks: none + :depth: 2 + :class: singlecol + +.. facet:: + :name: genre + :values: reference + +.. meta:: + :keywords: search, atlas, read + +Overview +-------- + +In this guide, you can learn how to query an Atlas Search index and use advanced search functionality for your applications. To query the seach index, use a ``$search`` aggregation pipeline stage with {+driver-short+}. + +To learn more about the ``$search`` pipeline stage, see :manual:`$search +`. + +.. note:: Only Available on Atlas for MongoDB v4.2 and Later + The ``$search`` aggregation-pipeline operator is available only for collections hosted + on :atlas:`MongoDB Atlas ` clusters running MongoDB v4.2 or later that are + covered by an :atlas:`Atlas search index `. + To learn more about the required setup and the functionality of this operator, + see the :ref:`Atlas Search ` documentation. + +Sample Data +~~~~~~~~~~~ + +The examples in this guide use the ``sample_mflix.movies`` collection +from the :atlas:`Atlas sample datasets `. To learn how to create a +free MongoDB Atlas cluster and load the sample datasets, see +:ref:``. + +Create an Atlas Search Index +---------------------------- + +Before you can perform a search on an Atlas collection, you must first create an **Atlas +Search index** on the collection. An Atlas Search index is a data structure that +categorizes data in a searchable format. To learn how to create an Atlas Search Index +see the :ref:`pymongo-atlas-search-index` documentation. + +Search Your Data +---------------- + +To use the ``$search`` aggregation pipeline stage, you must select an Atlas Search query operator that specifies the type of query you run. You can also optionally select a collector that groups results by values or ranges. To see a table of all the operators and collectors available in Atlas Search, see :atlas:`Use Operators and Collectors in Atlas Search Queries `. + +The following example uses the ``phrase`` operator, which performs search for documents containing an ordered sequence of terms. To learn more about the ``phrase`` operator, see :atlas:`Phrase ` in the Atlas guide. + +The example performs a basic search of the ``title`` field for the query string ``new york``. There is no +The query also includes a: + +- :pipeline:`$limit` stage to limit the output to 10 results. +- :pipeline:`$project` stage to exclude all fields except + ``title`` and add a field named ``score``. + +.. code-block:: python + :copyable: true + client = pymongo.MongoClient('') + result = client['sample_mflix']['movies'].aggregate([ + { + "$search": { + "phrase": { + "path": "title", + "query": "new york" + } + } + }, + { $limit: 10 }, + { + $project: { + "_id": 0, + "title": 1, + score: { $meta: "searchScore" } + } + } + ]) + for i in result: + print(i) + +.. output:: + :language: shell + :linenos: + :visible: false + + [ + { title: 'New York, New York', score: 6.786321640014648 } + { title: 'New York', score: 6.258549213409424 } + { title: 'New York Stories', score: 5.3813982009887695 } + { title: 'New York Minute', score: 5.3813982009887695 } + { title: 'Synecdoche, New York', score: 5.3813982009887695 } + { title: 'New York Doll', score: 5.3813982009887695 } + { title: 'Little New York', score: 5.3813982009887695 } + { title: 'Escape from New York', score: 4.719893455505371 } + { title: 'Naked in New York', score: 4.719893455505371 } + { title: 'Autumn in New York', score: 4.719893455505371 } + ] + +Next Steps +---------- + +Now that you've run a query using Atlas Search, review the Atlas Search :atlas:`documentation +` to learn more about the different :atlas:`operators +` and other queries you can run. More query examples using +MongoDB Query Language (MQL) are available througout the Atlas :atlas:`documentation +`. \ No newline at end of file diff --git a/source/index.txt b/source/index.txt index 60e76d5f..9a12a4f6 100644 --- a/source/index.txt +++ b/source/index.txt @@ -18,6 +18,7 @@ MongoDB {+driver-short+} Documentation Write Data Read Data Run a Database Command + Atlas Search Indexes Aggregation Security From 61417a037b4091d006302a62f3e9339aeb826247 Mon Sep 17 00:00:00 2001 From: Angela Date: Thu, 13 Mar 2025 16:17:32 -0400 Subject: [PATCH 02/20] fix indentation --- source/atlas-search.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/atlas-search.txt b/source/atlas-search.txt index b282874b..b3ef7aea 100644 --- a/source/atlas-search.txt +++ b/source/atlas-search.txt @@ -84,7 +84,7 @@ The query also includes a: } ]) for i in result: - print(i) + print(i) .. output:: :language: shell From a2810058afae55c820ee689cb17dadbac237c104 Mon Sep 17 00:00:00 2001 From: Angela Date: Thu, 13 Mar 2025 16:22:14 -0400 Subject: [PATCH 03/20] fix note --- source/atlas-search.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/source/atlas-search.txt b/source/atlas-search.txt index b3ef7aea..06fd4dd2 100644 --- a/source/atlas-search.txt +++ b/source/atlas-search.txt @@ -26,6 +26,7 @@ To learn more about the ``$search`` pipeline stage, see :manual:`$search `. .. note:: Only Available on Atlas for MongoDB v4.2 and Later + The ``$search`` aggregation-pipeline operator is available only for collections hosted on :atlas:`MongoDB Atlas ` clusters running MongoDB v4.2 or later that are covered by an :atlas:`Atlas search index `. From 1e1cf712d5a3ee7ad93858c6397143c14386374c Mon Sep 17 00:00:00 2001 From: Angela Date: Thu, 13 Mar 2025 16:23:55 -0400 Subject: [PATCH 04/20] fix code --- source/atlas-search.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/atlas-search.txt b/source/atlas-search.txt index 06fd4dd2..e1b740a8 100644 --- a/source/atlas-search.txt +++ b/source/atlas-search.txt @@ -56,7 +56,7 @@ To use the ``$search`` aggregation pipeline stage, you must select an Atlas Sear The following example uses the ``phrase`` operator, which performs search for documents containing an ordered sequence of terms. To learn more about the ``phrase`` operator, see :atlas:`Phrase ` in the Atlas guide. -The example performs a basic search of the ``title`` field for the query string ``new york``. There is no +The example performs a basic search of the ``title`` field for the query string ``new york``. The query also includes a: - :pipeline:`$limit` stage to limit the output to 10 results. @@ -65,6 +65,7 @@ The query also includes a: .. code-block:: python :copyable: true + client = pymongo.MongoClient('') result = client['sample_mflix']['movies'].aggregate([ { From 91e0cb86da6e58e302ef465ee02e7bfac5b0230e Mon Sep 17 00:00:00 2001 From: Angela Date: Thu, 13 Mar 2025 16:40:13 -0400 Subject: [PATCH 05/20] fix code examples --- source/atlas-search.txt | 62 +++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/source/atlas-search.txt b/source/atlas-search.txt index e1b740a8..50f85446 100644 --- a/source/atlas-search.txt +++ b/source/atlas-search.txt @@ -63,14 +63,16 @@ The query also includes a: - :pipeline:`$project` stage to exclude all fields except ``title`` and add a field named ``score``. -.. code-block:: python +.. io-code-block:: :copyable: true + + .. input:: python - client = pymongo.MongoClient('') - result = client['sample_mflix']['movies'].aggregate([ - { - "$search": { - "phrase": { + client = pymongo.MongoClient('') + result = client['sample_mflix']['movies'].aggregate([ + { + "$search": { + "phrase": { "path": "title", "query": "new york" } @@ -78,33 +80,33 @@ The query also includes a: }, { $limit: 10 }, { - $project: { - "_id": 0, - "title": 1, - score: { $meta: "searchScore" } + $project: { + "_id": 0, + "title": 1, + score: { $meta: "searchScore" } } } ]) - for i in result: - print(i) - -.. output:: - :language: shell - :linenos: - :visible: false - - [ - { title: 'New York, New York', score: 6.786321640014648 } - { title: 'New York', score: 6.258549213409424 } - { title: 'New York Stories', score: 5.3813982009887695 } - { title: 'New York Minute', score: 5.3813982009887695 } - { title: 'Synecdoche, New York', score: 5.3813982009887695 } - { title: 'New York Doll', score: 5.3813982009887695 } - { title: 'Little New York', score: 5.3813982009887695 } - { title: 'Escape from New York', score: 4.719893455505371 } - { title: 'Naked in New York', score: 4.719893455505371 } - { title: 'Autumn in New York', score: 4.719893455505371 } - ] + for i in result: + print(i) + + .. output:: + :language: shell + :linenos: + :visible: false + + [ + { title: 'New York, New York', score: 6.786321640014648 } + { title: 'New York', score: 6.258549213409424 } + { title: 'New York Stories', score: 5.3813982009887695 } + { title: 'New York Minute', score: 5.3813982009887695 } + { title: 'Synecdoche, New York', score: 5.3813982009887695 } + { title: 'New York Doll', score: 5.3813982009887695 } + { title: 'Little New York', score: 5.3813982009887695 } + { title: 'Escape from New York', score: 4.719893455505371 } + { title: 'Naked in New York', score: 4.719893455505371 } + { title: 'Autumn in New York', score: 4.719893455505371 } + ] Next Steps ---------- From 3f5dafbbc556c00239ac44b7dbc4194652a33a51 Mon Sep 17 00:00:00 2001 From: Angela Date: Thu, 13 Mar 2025 17:01:36 -0400 Subject: [PATCH 06/20] fix code --- source/atlas-search.txt | 55 +++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/source/atlas-search.txt b/source/atlas-search.txt index 50f85446..32c6e23e 100644 --- a/source/atlas-search.txt +++ b/source/atlas-search.txt @@ -66,36 +66,37 @@ The query also includes a: .. io-code-block:: :copyable: true - .. input:: python - - client = pymongo.MongoClient('') - result = client['sample_mflix']['movies'].aggregate([ - { - "$search": { - "phrase": { - "path": "title", - "query": "new york" - } - } - }, - { $limit: 10 }, + .. input:: + :language: python + + client = pymongo.MongoClient('') + result = client['sample_mflix']['movies'].aggregate([ { - $project: { - "_id": 0, - "title": 1, - score: { $meta: "searchScore" } - } + "$search": { + "phrase": { + "path": "title", + "query": "new york" + } + } + }, + { $limit: 10 }, + { + $project: { + "_id": 0, + "title": 1, + score: { $meta: "searchScore" } } - ]) - for i in result: - print(i) + } + ]) + + for i in result: + print(i) - .. output:: - :language: shell - :linenos: - :visible: false + .. output:: + :language: none + :visible: false - [ + [ { title: 'New York, New York', score: 6.786321640014648 } { title: 'New York', score: 6.258549213409424 } { title: 'New York Stories', score: 5.3813982009887695 } @@ -106,7 +107,7 @@ The query also includes a: { title: 'Escape from New York', score: 4.719893455505371 } { title: 'Naked in New York', score: 4.719893455505371 } { title: 'Autumn in New York', score: 4.719893455505371 } - ] + ] Next Steps ---------- From 9fb0ae18601104d08fb895c1a984c8e4be3eb9bb Mon Sep 17 00:00:00 2001 From: Angela Date: Thu, 13 Mar 2025 17:12:41 -0400 Subject: [PATCH 07/20] code spaing --- source/atlas-search.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/source/atlas-search.txt b/source/atlas-search.txt index 32c6e23e..5763a19d 100644 --- a/source/atlas-search.txt +++ b/source/atlas-search.txt @@ -77,7 +77,7 @@ The query also includes a: "path": "title", "query": "new york" } - } + } }, { $limit: 10 }, { @@ -85,10 +85,10 @@ The query also includes a: "_id": 0, "title": 1, score: { $meta: "searchScore" } - } - } - ]) - + } + } + ]) + for i in result: print(i) From 23a66b38177f4294d2c01c8e9ec0e1694e70a34b Mon Sep 17 00:00:00 2001 From: Angela Date: Thu, 13 Mar 2025 17:17:35 -0400 Subject: [PATCH 08/20] Fix spacing --- source/atlas-search.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/source/atlas-search.txt b/source/atlas-search.txt index 5763a19d..5879dd0c 100644 --- a/source/atlas-search.txt +++ b/source/atlas-search.txt @@ -81,12 +81,12 @@ The query also includes a: }, { $limit: 10 }, { - $project: { - "_id": 0, - "title": 1, - score: { $meta: "searchScore" } - } - } + $project: { + "_id": 0, + "title": 1, + score: { $meta: "searchScore" } + } + } ]) for i in result: From 42ca676c40fd21ac47601010fdcf4bf6a993e456 Mon Sep 17 00:00:00 2001 From: Angela Date: Thu, 13 Mar 2025 17:23:23 -0400 Subject: [PATCH 09/20] spacing --- source/atlas-search.txt | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/source/atlas-search.txt b/source/atlas-search.txt index 5879dd0c..2fe5cd5d 100644 --- a/source/atlas-search.txt +++ b/source/atlas-search.txt @@ -76,18 +76,18 @@ The query also includes a: "phrase": { "path": "title", "query": "new york" - } - } - }, - { $limit: 10 }, - { - $project: { - "_id": 0, - "title": 1, - score: { $meta: "searchScore" } - } - } - ]) + } + } + }, + { $limit: 10 }, + { + $project: { + "_id": 0, + "title": 1, + score: { $meta: "searchScore" } + } + } + ]) for i in result: print(i) From 1f1902211130cde3a55a897578fc96acb9ce0ea0 Mon Sep 17 00:00:00 2001 From: Angela Date: Thu, 13 Mar 2025 17:55:20 -0400 Subject: [PATCH 10/20] fix code to be runnable --- source/atlas-search.txt | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/source/atlas-search.txt b/source/atlas-search.txt index 2fe5cd5d..f57ffb85 100644 --- a/source/atlas-search.txt +++ b/source/atlas-search.txt @@ -79,12 +79,12 @@ The query also includes a: } } }, - { $limit: 10 }, + { "$limit": 10 }, { - $project: { + "$project": { "_id": 0, "title": 1, - score: { $meta: "searchScore" } + "score": { "$meta": "searchScore" } } } ]) @@ -96,18 +96,16 @@ The query also includes a: :language: none :visible: false - [ - { title: 'New York, New York', score: 6.786321640014648 } - { title: 'New York', score: 6.258549213409424 } - { title: 'New York Stories', score: 5.3813982009887695 } - { title: 'New York Minute', score: 5.3813982009887695 } - { title: 'Synecdoche, New York', score: 5.3813982009887695 } - { title: 'New York Doll', score: 5.3813982009887695 } - { title: 'Little New York', score: 5.3813982009887695 } - { title: 'Escape from New York', score: 4.719893455505371 } - { title: 'Naked in New York', score: 4.719893455505371 } - { title: 'Autumn in New York', score: 4.719893455505371 } - ] + { title: 'New York, New York', score: 6.786321640014648 } + { title: 'New York', score: 6.258549213409424 } + { title: 'New York Stories', score: 5.3813982009887695 } + { title: 'New York Minute', score: 5.3813982009887695 } + { title: 'Synecdoche, New York', score: 5.3813982009887695 } + { title: 'New York Doll', score: 5.3813982009887695 } + { title: 'Little New York', score: 5.3813982009887695 } + { title: 'Escape from New York', score: 4.719893455505371 } + { title: 'Naked in New York', score: 4.719893455505371 } + { title: 'Autumn in New York', score: 4.719893455505371 } Next Steps ---------- From b70545d3c208686614f4e09e4ef1921f31ac4bbe Mon Sep 17 00:00:00 2001 From: Angela Date: Thu, 13 Mar 2025 17:56:47 -0400 Subject: [PATCH 11/20] add index --- source/atlas-search.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source/atlas-search.txt b/source/atlas-search.txt index f57ffb85..9dafc720 100644 --- a/source/atlas-search.txt +++ b/source/atlas-search.txt @@ -69,10 +69,11 @@ The query also includes a: .. input:: :language: python - client = pymongo.MongoClient('') - result = client['sample_mflix']['movies'].aggregate([ + client = pymongo.MongoClient("") + result = client["sample_mflix"]["movies"].aggregate([ { "$search": { + "index": "pymongoindex", "phrase": { "path": "title", "query": "new york" From 832bc704da498910ba5254687fed4d188ae199bb Mon Sep 17 00:00:00 2001 From: Angela Date: Fri, 14 Mar 2025 14:33:13 -0400 Subject: [PATCH 12/20] js feedback --- source/atlas-search.txt | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/source/atlas-search.txt b/source/atlas-search.txt index 9dafc720..649ac0b5 100644 --- a/source/atlas-search.txt +++ b/source/atlas-search.txt @@ -20,10 +20,12 @@ Atlas Search Overview -------- -In this guide, you can learn how to query an Atlas Search index and use advanced search functionality for your applications. To query the seach index, use a ``$search`` aggregation pipeline stage with {+driver-short+}. +In this guide, you can learn how to query an Atlas Search index and use advanced search +functionality for your {+driver-short+} applications. You can query a search index by +using a ``$search`` aggregation pipeline stage. -To learn more about the ``$search`` pipeline stage, see :manual:`$search -`. +To learn more about the ``$search`` pipeline stage, see the :manual:`$search +` guide in the {+mdb-server+} manual. .. note:: Only Available on Atlas for MongoDB v4.2 and Later @@ -47,20 +49,26 @@ Create an Atlas Search Index Before you can perform a search on an Atlas collection, you must first create an **Atlas Search index** on the collection. An Atlas Search index is a data structure that categorizes data in a searchable format. To learn how to create an Atlas Search Index -see the :ref:`pymongo-atlas-search-index` documentation. +see :ref:`pymongo-atlas-search-index`. Search Your Data ---------------- -To use the ``$search`` aggregation pipeline stage, you must select an Atlas Search query operator that specifies the type of query you run. You can also optionally select a collector that groups results by values or ranges. To see a table of all the operators and collectors available in Atlas Search, see :atlas:`Use Operators and Collectors in Atlas Search Queries `. +To use the ``$search`` aggregation pipeline stage, you must specify an Atlas Search query +operator that indicates the type of query you want to run. You can also optionally specify +a collector that groups results by values or ranges. To view a table of all the operators +and collectors available with Atlas Search, see :atlas:`Use Operators and Collectors in +Atlas Search Queries `. -The following example uses the ``phrase`` operator, which performs search for documents containing an ordered sequence of terms. To learn more about the ``phrase`` operator, see :atlas:`Phrase ` in the Atlas guide. +The following example uses the ``phrase`` operator, which performs a search for documents +that contain an ordered sequence of terms. To learn more about the ``phrase`` operator, see +:atlas:`Phrase ` in the Atlas guide. -The example performs a basic search of the ``title`` field for the query string ``new york``. -The query also includes a: +The example performs a basic search of the ``title`` field for the query string ``"new york"``. +The query also includes the following stages: -- :pipeline:`$limit` stage to limit the output to 10 results. -- :pipeline:`$project` stage to exclude all fields except +- :pipeline:`$limit`, to limit the output to 10 results. +- :pipeline:`$project`, to exclude all fields except ``title`` and add a field named ``score``. .. io-code-block:: @@ -108,11 +116,12 @@ The query also includes a: { title: 'Naked in New York', score: 4.719893455505371 } { title: 'Autumn in New York', score: 4.719893455505371 } -Next Steps ----------- +Additional Information +---------------------- -Now that you've run a query using Atlas Search, review the Atlas Search :atlas:`documentation -` to learn more about the different :atlas:`operators -` and other queries you can run. More query examples using -MongoDB Query Language (MQL) are available througout the Atlas :atlas:`documentation +To learn more about the different Atlas Search :atlas:`operators +` and other queries you can run, see the +Atlas Search :atlas:`documentation `. + +You can view more query examples througout the Atlas :atlas:`documentation `. \ No newline at end of file From 4c4d58049ed515c20ff4b0172cc72f3099aadc10 Mon Sep 17 00:00:00 2001 From: Angela Date: Fri, 14 Mar 2025 15:23:44 -0400 Subject: [PATCH 13/20] js feedback --- source/atlas-search.txt | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/source/atlas-search.txt b/source/atlas-search.txt index 649ac0b5..7f98cee0 100644 --- a/source/atlas-search.txt +++ b/source/atlas-search.txt @@ -21,7 +21,7 @@ Overview -------- In this guide, you can learn how to query an Atlas Search index and use advanced search -functionality for your {+driver-short+} applications. You can query a search index by +functionality in your {+driver-short+} applications. You can query a search index by using a ``$search`` aggregation pipeline stage. To learn more about the ``$search`` pipeline stage, see the :manual:`$search @@ -48,7 +48,7 @@ Create an Atlas Search Index Before you can perform a search on an Atlas collection, you must first create an **Atlas Search index** on the collection. An Atlas Search index is a data structure that -categorizes data in a searchable format. To learn how to create an Atlas Search Index +categorizes data in a searchable format. To learn how to create an Atlas Search Index, see :ref:`pymongo-atlas-search-index`. Search Your Data @@ -61,8 +61,7 @@ and collectors available with Atlas Search, see :atlas:`Use Operators and Collec Atlas Search Queries `. The following example uses the ``phrase`` operator, which performs a search for documents -that contain an ordered sequence of terms. To learn more about the ``phrase`` operator, see -:atlas:`Phrase ` in the Atlas guide. +that contain an ordered sequence of terms. To learn more about the ``phrase`` operator, see the :atlas:`Phrase ` guide in the MongoDB Atlas documentation. The example performs a basic search of the ``title`` field for the query string ``"new york"``. The query also includes the following stages: @@ -119,9 +118,7 @@ The query also includes the following stages: Additional Information ---------------------- -To learn more about the different Atlas Search :atlas:`operators -` and other queries you can run, see the -Atlas Search :atlas:`documentation `. +To learn more about the available Atlas Search operators, see the :atlas:`Operators and Collectors ` guide in the MongoDB Atlas documentation. -You can view more query examples througout the Atlas :atlas:`documentation -`. \ No newline at end of file +For more information about Atlas Search, and to view more query examples, see the +:atlas:`Atlas Search documentation `. \ No newline at end of file From fde6b8c1e9ba3911b13ccb045a727a413aebde0c Mon Sep 17 00:00:00 2001 From: Angela Date: Mon, 17 Mar 2025 14:50:19 -0400 Subject: [PATCH 14/20] change query example --- source/atlas-search.txt | 76 +++++++++++++++++++++++++++-------------- 1 file changed, 50 insertions(+), 26 deletions(-) diff --git a/source/atlas-search.txt b/source/atlas-search.txt index 7f98cee0..a95b3b11 100644 --- a/source/atlas-search.txt +++ b/source/atlas-search.txt @@ -20,8 +20,8 @@ Atlas Search Overview -------- -In this guide, you can learn how to query an Atlas Search index and use advanced search -functionality in your {+driver-short+} applications. You can query a search index by +In this guide, you can learn how to query an Atlas Search index and use advanced full-text +search functionality in your {+driver-short+} applications. You can query a search index by using a ``$search`` aggregation pipeline stage. To learn more about the ``$search`` pipeline stage, see the :manual:`$search @@ -48,7 +48,7 @@ Create an Atlas Search Index Before you can perform a search on an Atlas collection, you must first create an **Atlas Search index** on the collection. An Atlas Search index is a data structure that -categorizes data in a searchable format. To learn how to create an Atlas Search Index, +categorizes data in a searchable format. To learn how to create an Atlas Search index, see :ref:`pymongo-atlas-search-index`. Search Your Data @@ -79,13 +79,31 @@ The query also includes the following stages: client = pymongo.MongoClient("") result = client["sample_mflix"]["movies"].aggregate([ { - "$search": { - "index": "pymongoindex", - "phrase": { - "path": "title", - "query": "new york" - } - } + "$search": { + "index": "pymongoindex", + "compound": { + "mustNot": [ + { + "text": { + "query": [ + "Comedy" + ], + "path": "genres" + } + } + ], + "must": [ + { + "text": { + "query": [ + "new york" + ], + "path": "title" + } + } + ], + } + } }, { "$limit": 10 }, { @@ -93,9 +111,9 @@ The query also includes the following stages: "_id": 0, "title": 1, "score": { "$meta": "searchScore" } - } - } - ]) + } + } + ]) for i in result: print(i) @@ -104,21 +122,27 @@ The query also includes the following stages: :language: none :visible: false - { title: 'New York, New York', score: 6.786321640014648 } - { title: 'New York', score: 6.258549213409424 } - { title: 'New York Stories', score: 5.3813982009887695 } - { title: 'New York Minute', score: 5.3813982009887695 } - { title: 'Synecdoche, New York', score: 5.3813982009887695 } - { title: 'New York Doll', score: 5.3813982009887695 } - { title: 'Little New York', score: 5.3813982009887695 } - { title: 'Escape from New York', score: 4.719893455505371 } - { title: 'Naked in New York', score: 4.719893455505371 } - { title: 'Autumn in New York', score: 4.719893455505371 } + {'title': 'New York, New York', 'score': 6.786379814147949} + {'title': 'New York', 'score': 6.258603096008301} + {'title': 'New York Doll', 'score': 5.381444931030273} + {'title': 'Escape from New York', 'score': 4.719935417175293} + {'title': 'Autumn in New York', 'score': 4.719935417175293} + {'title': 'Sleepless in New York', 'score': 4.719935417175293} + {'title': 'Gangs of New York', 'score': 4.719935417175293} + {'title': 'Sherlock Holmes in New York', 'score': 4.203253746032715} + {'title': 'New York: A Documentary Film', 'score': 4.203253746032715} + {'title': 'An Englishman in New York', 'score': 4.203253746032715} Additional Information ---------------------- -To learn more about the available Atlas Search operators, see the :atlas:`Operators and Collectors ` guide in the MongoDB Atlas documentation. - +To learn more about the available Atlas Search operators, see the :atlas:`Operators and +Collectors ` guide in the MongoDB Atlas +documentation. +ß For more information about Atlas Search, and to view more query examples, see the -:atlas:`Atlas Search documentation `. \ No newline at end of file +:atlas:`Atlas Search documentation `. + +If you'd like to perform vector searches on your data stored in Atlas, you must use Atlas +Vector Search. To learn more about Atlas Vector Search, see the :atlas:`Atlas Vector +Search documentation `. \ No newline at end of file From 8d345d8bc6a4163ab1b9ccc8b0db7e167a274d1e Mon Sep 17 00:00:00 2001 From: Angela Date: Mon, 17 Mar 2025 14:56:22 -0400 Subject: [PATCH 15/20] change query leadin --- source/atlas-search.txt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/source/atlas-search.txt b/source/atlas-search.txt index a95b3b11..9367c831 100644 --- a/source/atlas-search.txt +++ b/source/atlas-search.txt @@ -60,10 +60,15 @@ a collector that groups results by values or ranges. To view a table of all the and collectors available with Atlas Search, see :atlas:`Use Operators and Collectors in Atlas Search Queries `. -The following example uses the ``phrase`` operator, which performs a search for documents -that contain an ordered sequence of terms. To learn more about the ``phrase`` operator, see the :atlas:`Phrase ` guide in the MongoDB Atlas documentation. +The following example uses the ``compound`` operator to combine several operators into a +single query. To learn more about the `compound`` operator, see the :atlas:`Compound +` guide in the MongoDB Atlas documentation. + +The query has the following search criteria: + +- The genres field must not contain Comedy. +- The title field must contain the string ``"new york"``. -The example performs a basic search of the ``title`` field for the query string ``"new york"``. The query also includes the following stages: - :pipeline:`$limit`, to limit the output to 10 results. From fd1b40ce3c21dc207be0d96d906535d3e9c80cc8 Mon Sep 17 00:00:00 2001 From: Angela Date: Mon, 17 Mar 2025 14:57:52 -0400 Subject: [PATCH 16/20] formatting --- source/atlas-search.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/atlas-search.txt b/source/atlas-search.txt index 9367c831..5346c8a0 100644 --- a/source/atlas-search.txt +++ b/source/atlas-search.txt @@ -66,8 +66,8 @@ single query. To learn more about the `compound`` operator, see the :atlas:`Comp The query has the following search criteria: -- The genres field must not contain Comedy. -- The title field must contain the string ``"new york"``. +- The ``genres`` field must not contain ``Comedy``. +- The ``title`` field must contain the string ``new york``. The query also includes the following stages: From da20d885f4976b7f1358303f99dfc1a02a74ebf3 Mon Sep 17 00:00:00 2001 From: Angela Date: Mon, 17 Mar 2025 14:59:40 -0400 Subject: [PATCH 17/20] remove random symbol --- source/atlas-search.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/atlas-search.txt b/source/atlas-search.txt index 5346c8a0..86af34d1 100644 --- a/source/atlas-search.txt +++ b/source/atlas-search.txt @@ -144,7 +144,7 @@ Additional Information To learn more about the available Atlas Search operators, see the :atlas:`Operators and Collectors ` guide in the MongoDB Atlas documentation. -ß + For more information about Atlas Search, and to view more query examples, see the :atlas:`Atlas Search documentation `. From bfc9606f144f86774e862bac3c0b5f43111281a6 Mon Sep 17 00:00:00 2001 From: Angela Date: Mon, 17 Mar 2025 15:05:09 -0400 Subject: [PATCH 18/20] fix quotes --- source/atlas-search.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/atlas-search.txt b/source/atlas-search.txt index 86af34d1..7bcdc255 100644 --- a/source/atlas-search.txt +++ b/source/atlas-search.txt @@ -61,7 +61,7 @@ and collectors available with Atlas Search, see :atlas:`Use Operators and Collec Atlas Search Queries `. The following example uses the ``compound`` operator to combine several operators into a -single query. To learn more about the `compound`` operator, see the :atlas:`Compound +single query. To learn more about the ``compound`` operator, see the :atlas:`Compound ` guide in the MongoDB Atlas documentation. The query has the following search criteria: From 3373359f304aac6e06437351023c7cb2429e7bd2 Mon Sep 17 00:00:00 2001 From: Angela Date: Mon, 17 Mar 2025 15:05:27 -0400 Subject: [PATCH 19/20] copy edit --- source/atlas-search.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/atlas-search.txt b/source/atlas-search.txt index 7bcdc255..f76c405d 100644 --- a/source/atlas-search.txt +++ b/source/atlas-search.txt @@ -62,7 +62,7 @@ Atlas Search Queries `. The following example uses the ``compound`` operator to combine several operators into a single query. To learn more about the ``compound`` operator, see the :atlas:`Compound -` guide in the MongoDB Atlas documentation. +` operator guide in the MongoDB Atlas documentation. The query has the following search criteria: From f8045194aef7e0bc6902e25b044c90ae00307967 Mon Sep 17 00:00:00 2001 From: Angela Date: Mon, 17 Mar 2025 15:05:51 -0400 Subject: [PATCH 20/20] change query --- source/atlas-search.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/atlas-search.txt b/source/atlas-search.txt index f76c405d..5499704f 100644 --- a/source/atlas-search.txt +++ b/source/atlas-search.txt @@ -67,7 +67,7 @@ single query. To learn more about the ``compound`` operator, see the :atlas:`Com The query has the following search criteria: - The ``genres`` field must not contain ``Comedy``. -- The ``title`` field must contain the string ``new york``. +- The ``title`` field must contain the string ``New York``. The query also includes the following stages: @@ -101,7 +101,7 @@ The query also includes the following stages: { "text": { "query": [ - "new york" + "New York" ], "path": "title" }