WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

MongoDB - Regular Expression


MongoDB also affords functionality of normal expression for string sample matching using the $regex operator.

MongoDB uses Perl Compatible Regular Expression as ordinary expression language.

   "post_text": "experience the mongodb articles on welookups",
   "tags": [
      "mongodb",
      "welookups"
   ]


Using regex Expression

The following regex query searches for all of the posts containing string welookups in it
>db.Posts.Locate(post_text:$regex:"welookups")
The equal question can also be written as
>db.Posts.Locate(post_text:/welookups/)

Using regex Expression with Case Insensitive

we use the $alternatives parameter with price $i. The following command will look for strings having the word welookups, no matter smaller or capital case
>db.Posts.Discover(post_text:$regex:"welookups",$options:"$i")
One of the effects back from this query is the following record which incorporates the phrase welookups in one of a kind instances

   "_id" : ObjectId("53493d37d852429c10000004"),
   "post_text" : "whats up! This is my post on welookups", 
   "tags" : [ "welookups" ]
 
 

Using regex for Array Elements

We also can use the idea of regex on array area. This is specifically very essential whilst we enforce the functionality of tags. So, in case you need to search for all the posts having tags starting from the phrase educational (both welookups academic ), you could use the following code

>db.Posts.Discover(tags:$regex:"academic")





Welookups is optimized for learning.Copy right 2018 kumar aditya singh .
All Right Reserved and you agree to have read and accepted our term and condition.
All Rights Reserved.