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.drop();
db.articles.createIndex( { subject: "text" } )
db.articles.insert(
[
{ _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.