Articles → MONGODB → Text Index In Mongodb
Text Index In Mongodb
Purpose
Syntax
db.collection.createIndex({ fieldName: "text" });
Example
db.mycollection.createIndex({"name":"text"})
Performing Text Search
db.collection.find({ $text: { $search: "searchString" } })
$Meta Operator
db.collection.find(
{ $text: { $search: "your_search_query" } },
{ score: { $meta: "textScore" } }
)