Docs Menu

Docs HomeStart with Guides

Querying with the Compound Operator

In this guide, you will learn how to use multiple search operators in a compound query by using the aggregation pipeline.

Time required: 5 minutes

click to enlarge

Click the Collections tab.

click to enlarge

Click the sample_supplies database, then click the sales collection.


Click the Aggregation tab.


Click + Add Stage to begin creating your aggregation pipeline.


In the stage window, click on the dropdown menu labeled Select and select the $search stage.


Replace the placeholder code with the following query.

"compound": {
"filter": [{
"text": {
"query": "Online",
"path": "purchaseMethod"
"should": [{
"text": {
"query": "notepad",
"path": "items"

This query uses the compound operator with:

  • The filter clause to return only documents with a purchaseMethod of Online.

  • The should clause to return documents with an items field that contains notepad to have a higher score than those without.


In the right-hand pane, your results should include a list of documents that resemble the following sample document:

items: Array
0: Object
1: Object
2: Object
name: "notepad"
storeLocation: "Denver"
customer: Object
couponUsed: false
purchaseMethod: "Online"
_id: ObjectID('5bd761dcae323e45a93cd06e')
saleDate: 2013-11-22T18:49:45.212+00:00


The fields don't always appear in the same order for every returned document.

You can expand Array and Object fields to view their contents by clicking on them.

If you successfully completed the procedure in this guide, you have created an Atlas Search aggregation stage with a compound operator, and have seen how different clauses in the operator interact to focus your search results across multiple axes. In the next guide, you will learn how to group search results using facets.

What's Next
Querying with Facets
10 mins

Retrieve documents in MongoDB with counts of specific values.

Start Guide
Chapter 3
Atlas Search
  • Build a Dynamic Index
  • Build an Index with Static Field Mappings
  • Querying with the Compound Operator
  • Querying with Facets
Start with Guides →