MongoDB Text Search and Rockmongo

At first Text Search was a trial excremental however beginning from the configuration 2.6, the same is empowered as default in MongoDB. Anyway if you are utilizing past version of MongoDB, you need to empower text search  with the below code:


Making Text Index

Consider the accompanying under posts collection containing the post text and its tags:

{"post_text": "appreciate the MongoDB articles of J2eebrain",
"tags": [
"J2EEbrain "

We will make a content index on post_text field with the goal that we can seek inside our posts’ content:


Utilizing Text Index

Presently that we have made the content index on post_text field, we will search down all the post that have word J2EEbrain in their content.


The above command furnishes a  result which has J2EEbrain word in their post content:

{"_id" : ObjectId("53493d14d852429c10000002"),
"post_text" : "delight in the MongoDB articles on J2EEbrain ",
"labels" : [ "MongoDB", "J2EEbrain " ]
"_id" : ObjectId("53493d1fd852429c10000003"),
"post_text" : "composing excercises on MongoDB",
"labels" : [ "MongoDB", "excercise" ]

If you are utilizing old versions of MongoDB, you need to utilize the accompanying command:

db.posts.runCommand("text",{search:" J2EEbrain "})

Utilizing Text Search exceedingly enhances the search effectiveness as contrasted with ordinary search .

Erasing Text Index

To erase a current content index, first discover the name of index using query:


In the wake the name of your index from above query, run the accompanying command.The, post_text_text is the name of the index.


MongoDB Regular Expression

Regular Expressions are habitually utilized within all dialects to search down an example or word in any string. MongoDB likewise gives usefulness of consistent statement to string example matching utilizing the $regex administrator. MongoDB utilizes PCRE (Perl Compatible Regular Expression) as standard Regular Expression.

As like text search there is no need for any configuration or command to pursue regular expression

Consider the accompanying record structure under posts gathering containing the post content and its labels:

{"post_text": "revel in the MongoDB articles on J2EEbrain ",
"labels": [
"J2EEbrain "

Using regex Expression

The accompanying regex question hunt down all the posts containing string J2EEbrain in it:


The same inquiry can likewise be composed as:


Utilizing regex Expression with case insensitive

Inorder to make the search caseless we can utilise $options parameter with value$i.. The command  will search for strings having word J2eebrain, independent of more diminutive or capital case:


One of the results returned from this query is after record which contains word J2eebrain in different cases:

{"_id" : ObjectId("53493d37d852429c10000004"),
"post_text" : "hey! this is my post on J2eebrain",
"labels" : [ "J2eebrain" ]

Using regex for exhibit components:

We can likewise utilize the idea of regex on show field. This is especially extremely imperative when we actualize the usefulness of tags. Along these lines, if you need to look for all the posts having tags starting from word exercise you can utilize the accompanying code:


Optimizing Regular Expression Queries:

If the report fields are indexed, the inquiry will utilize make utilization of indexed qualities to match the customary outflow. This makes the inquiry quick as contrasted with the standard outflow checking the entire gathering.

If the regular expression is a prefix expression , all the matches are intended to begin with a certain string characters. For e.g., if the regex statement is ^tut, then the question need to hunt down just those strings that start with tut.

Working with Rockmongo

Rockmongo is a MongoDB admin instrument utilizing which you can deal with your server, databases, accumulations, records, indexes and a considerable measure more. It gives an extremely easy to understand path for perusing, written work and making archives. It is like PHPmyadmin apparatus for PHP and MySQL.

  • Making New Database:

To make another database, click on Databases tab. Click Create New Database. On the following screen, give the name of the new database and click on Create. You will see another database getting included the left board.

  • Making New Collection:

To make another collection inside a database, click on that database from left board. Click on the New Collection connect on top. Give the obliged name of the gathering. Don’t stress over alternate fields of Is Capped, Size and Max. Click on Create. Another collection will be made and you will have the capacity to see it in the left board.

  • Making New Document:

To make another archive, click on the collection  under which you need to include reports. When you click on an collection you will have the capacity to see all the reports inside that gathering recorded there. To make another report, click on the Insert join at the top. You can enter the record’s information either in JSON or array format and click on Save.

  • Fare/Import Data:

To import/send out information of any collection , click on that collection and afterward click on Export/Import interface on the top board. Take after the following guidelines to fare your information in zip and afterwards import the same compress record to import back information.