WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

MongoDB - Text Search


In this bankruptcy we are able to examine MongoDB - Text Search

Text Search uses stemming strategies to look for precise words within the string fields by way of losing stemming stop phrases like a, an, the, and so on. At gift, MongoDB supports around 15 languages.

Enabling Text Search

model 2.4, MongoDB aid Text Search. But in case you are using the previous version of MongoDB, you need to enable text seek with the following code
>db.adminCommand(setParameter:genuine,textSearchEnabled:actual)

Creating Text Index

Consider the subsequent document underneath posts series containing the publish textual content and its tags

   "post_text": "nobel prize 2018 winner physics Gérard Mourou, Arthur Ashkin, Donna Strickland",
   "tags": [
      "physics",
      "Donna Strickland"
   ]


We will create a text index on post_text field so that we will seek internal our posts' textual content
>db.posts.ensureIndex(post_text:"text")

Using Text Index

we are able to look for all of the posts having the phrase Donna Strickland in their text.
>db.Posts.Find($text:$search:"Donna Strickland")

The above command again the following end result files having the word Donna Strickland of their put up text

    "_id" : ObjectId("11254h4agr145yth34"),
    "post_text" : "nobel prize 2018 winner physics Gérard Mourou, Arthur Ashkin, Donna Strickland",
    "tags" : [ "physics", "Donna Strickland" ]


    "_id" : ObjectId("11254h4agr145yth35"),
    "post_text" : "nobel prize 2018 winner physics Gérard Mourou, Arthur Ashkin, Donna Strickland",
    "tags" : [ "physics", "winner" ]


If you are the use of old versions of MongoDB, you need to use the subsequent command
>db.Posts.RunCommand("text",seek:" winner ")

Deleting Text Index

To delete an existing textual content index, first find the name of index the usage of the subsequent query >db.posts.getIndexes() After getting the call of your index from above query, run the subsequent command. Here, post_text_text is the name of the index.
>db.Posts.DropIndex("post_text_text")





welookups is optimized for learning.© welookups 2018 -
All Right Reserved and you agree to have read and accepted our term and condition