Articles → MONGODB → Text Index In Mongodb

Text Index In Mongodb






Purpose





Syntax


db.collection.createIndex({ fieldName: "text" });



Example




Picture showing the sample document collection




db.mycollection.createIndex({"name":"text"})


Picture showing creating the text index in mongodb



Performing Text Search




db.collection.find({ $text: { $search: "searchString" } })


Picture showing searching the text on the column with text index



$Meta Operator






db.collection.find(
   { $text: { $search: "your_search_query" } },
   { score: { $meta: "textScore" } }
)


Picture showing using the $Meta operator in mongodb





Posted By  -  Karan Gupta
 
Posted On  -  Friday, May 10, 2024

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250