Unrecognized pipeline stage name: '$search'

I created a text index via mongodb compass.
While trying to test the search query locally(mongod on Ubuntu 20.04), I am getting this error.

  "ok": 0,
  "errmsg": "Unrecognized pipeline stage name: '$search'",
  "code": 40324,
  "codeName": "Location40324",
  "name": "MongoError"

Here is the aggregate pipeline snippet,

        $search: {
          text: {
            query: searchTerm,
            path: "note",

Hi Rahul, welcome to the community. To make use of Atlas Search you need to use the Atlas API or the Atlas UI (Click “Search in the cluster nav - click “create an [Atlas] Search index,” click “Query” or run the command you posted here.

Search indexes are different text indexes.

So, the $search is only available in the Atlas and not in the local instance ?

Correct, the $search Aggregation Pipeline stage is only available in MongoDB Atlas as an Atlas Search index is required, which cannot be created in a local deployment.

If you are looking to create a Text Index these can be queried using the $text operator as follows:

db.articles.createIndex( { subject: "text" } )
     { _id: 1, subject: "coffee", author: "xyz", views: 50 },
     { _id: 2, subject: "Coffee Shopping", author: "efg", views: 5 },
     { _id: 3, subject: "Baking a cake", author: "abc", views: 90  },
     { _id: 4, subject: "baking", author: "xyz", views: 100 },
     { _id: 5, subject: "Café Con Leche", author: "abc", views: 200 },
     { _id: 6, subject: "Сырники", author: "jkl", views: 80 },
     { _id: 7, subject: "coffee and cream", author: "efg", views: 10 },
     { _id: 8, subject: "Cafe con Leche", author: "xyz", views: 10 }
db.articles.find( { $text: { $search: "bake coffee cake" } } )

Note the $search field of the $text operator is not the same as the $search aggregation pipeline stage.

See the Text Search in the Aggregation Pipeline tutorial for more information as well.

1 Like