@@ -22,18 +22,18 @@ Overview
22
22
Retrieve documents in MongoDB with a query on multiple fields.
23
23
24
24
In this guide, you will learn how to use multiple search operators in
25
- a compound query using the aggregation pipeline.
25
+ a compound query by using the aggregation pipeline.
26
26
27
- .. time:: 15
27
+ .. time:: 5
28
28
29
29
What You'll Need
30
30
----------------
31
31
32
32
- A MongoDB account. See :ref:`guides-create-atlas-account`.
33
33
- An Atlas cluster. See :ref:`guides-create-a-cluster`.
34
34
- Sample datasets :ref:`loaded into your cluster <guides-load-sample-data>`.
35
- - A search index with default settings and dynamic indexing. See
36
- :ref:`guides-search-dynamic`.
35
+ - A search index with default settings and dynamic indexing.
36
+ To create a default dynamic index, see :ref:`guides-search-dynamic`.
37
37
38
38
Procedure
39
39
---------
@@ -43,79 +43,83 @@ Procedure
43
43
44
44
.. include:: /includes/navigate_to_collections.rst
45
45
46
- .. step:: In the right-hand pane, click ``sample_supplies``,
46
+ .. step:: Click the ``sample_supplies`` database,
47
47
then click the ``sales`` collection.
48
48
49
- .. step:: Run a query on your index using the Aggregation Pipeline .
49
+ .. step:: Run a compound query on your index in the :guilabel:`Aggregations` tab .
50
50
51
51
.. procedure::
52
52
:style: connected
53
53
54
54
.. step:: Click
55
55
the :guilabel:`Aggregation` tab.
56
56
57
- .. step:: If you do not see a pipeline with an initial
58
- stage window in the right pane, click
59
- :guilabel:`Create New` and select :guilabel:`Pipeline`.
60
-
57
+ .. step:: Click :guilabel:`+ Add Stage` to begin creating
58
+ your aggregation pipeline.
59
+
61
60
.. step:: In the stage window, click on the dropdown menu
62
- labeled :guilabel:`Select... ` and select the
61
+ labeled :guilabel:`Select` and select the
63
62
:guilabel:`$search` stage.
64
63
65
64
.. step:: Replace the placeholder code with the following
66
- ``compound`` operator:
65
+ query.
67
66
68
67
.. code-block:: json
69
68
70
69
{
71
- "compound": {
72
- "filter": [{
73
- "text": {
74
- "query": "Online",
75
- "path": "purchaseMethod"
76
- }
77
- }],
78
- "should": [{
79
- "text": {
80
- "query": "notepad",
81
- "path": "items"
82
- }
83
- }]
84
- }
70
+ "compound": {
71
+ "filter": [{
72
+ "text": {
73
+ "query": "Online",
74
+ "path": "purchaseMethod"
75
+ }
76
+ }],
77
+ "should": [{
78
+ "text": {
79
+ "query": "notepad",
80
+ "path": "items"
81
+ }
82
+ }]
83
+ }
85
84
}
86
85
87
- .. step:: Review the results of the compound search in the
88
- right-hand pane. Your results should include the fields listed
89
- in the following sample document.
86
+ This query uses the ``compound`` operator with:
87
+
88
+ - The ``filter`` clause to return only documents
89
+ with a ``purchaseMethod`` of ``Online``.
90
+ - The ``should`` clause to return documents
91
+ with an ``items`` field that contains ``notepad`` to have
92
+ a higher score than those without.
93
+
94
+ .. step:: Review the results of the compound query.
90
95
91
- .. note::
92
-
93
- The fields will not always appear in the same order
94
- for every returned document.
96
+ In the right-hand pane, your results should include a list
97
+ of documents that resemble the following sample document:
95
98
96
99
.. code-block:: json
97
100
:copyable: false
98
101
99
102
items: Array
103
+ 0: Object
104
+ 1: Object
105
+ 2: Object
106
+ name: "notepad"
107
+ ...
100
108
storeLocation: "Denver"
101
109
customer: Object
102
110
couponUsed: false
103
111
purchaseMethod: "Online"
104
112
_id: ObjectID('5bd761dcae323e45a93cd06e')
105
113
saleDate: 2013-11-22T18:49:45.212+00:00
106
114
115
+ .. note::
116
+
117
+ The fields don't always appear in the same order
118
+ for every returned document.
119
+
107
120
You can expand ``Array`` and ``Object`` fields to view their
108
121
contents by clicking on them.
109
122
110
- Due to the ``filter`` operator, only records with a
111
- ``purchaseMethod`` value of ``Online`` appear.
112
- Additionally, due to the ``should`` operator,
113
- records with an ``items`` value of ``notepad`` score
114
- higher than those without.
115
-
116
- You now have a ``$search`` aggregation stage with a compound
117
- search definition.
118
-
119
123
Summary
120
124
-------
121
125
0 commit comments