{"id":55690,"date":"2018-02-27T15:00:36","date_gmt":"2018-02-27T13:00:36","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=55690"},"modified":"2018-02-27T11:21:48","modified_gmt":"2018-02-27T09:21:48","slug":"mongodb-indexing-example","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-indexing-example\/","title":{"rendered":"MongoDB Indexing Example"},"content":{"rendered":"<p>Hello readers, in Mongo database, an index is a data structure that holds the specific data of the documents. In this tutorial, we will understand the <span style=\"text-decoration: underline;\">Mongo database indexing<\/span> to improve the performance of the search query.<\/p>\n<h2>1. Introduction<\/h2>\n<p>If you have installed the MongoDB application (<em>version 3.6<\/em>) on Windows or Ubuntu operating system and you wish to learn the indexing in Mongo database then follow the below steps. It is very simple. But before moving further let&#8217;s take a look at the Mongo database and its features.<\/p>\n<h3>1.1 What is MongoDB?<\/h3>\n<ul>\n<li>MongoDB is a high-performance <em>NoSQL database<\/em> where each database has collections which in turn has documents. Each document has a different number of fields, size, content, and is stored in a JSON-like format (i.e. Binary JSON (<a href=\"https:\/\/en.wikipedia.org\/wiki\/BSON\" target=\"_blank\" rel=\"noopener\">BSN<\/a>)<\/li>\n<li>The documents in MongoDB doesn\u2019t need to have a schema defined beforehand. Instead, the fields (i.e. <em>records<\/em>) can be created on the go<\/li>\n<li>Data model available within the MongoDB allows developers to represent the hierarchical relationships, store arrays, and other more complex structures easily<\/li>\n<li>This NoSQL solution often comes with embedding, auto-sharding, and onboard replication for better scalability and high availability<\/li>\n<\/ul>\n<h3>1.2 Why MongoDB?<\/h3>\n<ul>\n<li>As a NoSQL type database, MongoDB stores the data in the form of a document. Thus, MongoDB offers more flexibility<\/li>\n<li>This database supports search by field-name, range queries, and the regular expressions. It often provides queries to return the particular fields inside the documents<\/li>\n<li>MongoDB offers <em>indexes<\/em> to improve the <em>search performance<\/em> within the NoSQL database<\/li>\n<li>To offer horizontal scalability, MongoDB uses sharding by splitting the data across the many MongoDB occurrences<\/li>\n<li><strong>Replication<\/strong>: MongoDB can give high availability with the replica sets<\/li>\n<\/ul>\n<h3>1.3 Indexing in Mongo Database<\/h3>\n<p><span style=\"text-decoration: underline;\">Indexing<\/span> in Mongo database is a data structure that stores the few fields of a document in a structure that is easy to traverse. This concept increases the search operations performance and helps in the following functions:<\/p>\n<ul>\n<li>Search operation is performed on the indexes that hold only a set of data without a complete scan of the Mongo collection<\/li>\n<li>Store the field values in the order of value<\/li>\n<li>Support the range-based equality match queries<\/li>\n<\/ul>\n<p><figure id=\"attachment_55763\" aria-describedby=\"caption-attachment-55763\" style=\"width: 849px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/02\/mongodb-index-project-archi-guide-v1.jpg\"><img decoding=\"async\" class=\"wp-image-55763 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/02\/mongodb-index-project-archi-guide-v1.jpg\" alt=\"Fig. 1: Pictorial representation of an Index in the Mongo collection\" width=\"849\" height=\"312\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/02\/mongodb-index-project-archi-guide-v1.jpg 849w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/02\/mongodb-index-project-archi-guide-v1-300x110.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/02\/mongodb-index-project-archi-guide-v1-768x282.jpg 768w\" sizes=\"(max-width: 849px) 100vw, 849px\" \/><\/a><figcaption id=\"caption-attachment-55763\" class=\"wp-caption-text\">Fig. 1: Pictorial representation of an Index in the Mongo collection<\/figcaption><\/figure><\/p>\n<h4>1.3.1 Types of Index in Mongo database<\/h4>\n<p>Below is the list of the indexes available in the Mongo database.<\/p>\n<ul>\n<li><strong>Default _id<\/strong>: Each document in a Mongo collection has an index on the default <code>_id<\/code> field. This index is unique and restricts clients from adding the two documents with the same value<\/li>\n<li><strong>Single Field<\/strong>: For a single field index, Mongo database can traverse the indexes either in the ascending or the descending order to do the sort operations<\/li>\n<li><strong>Compound Index<\/strong>: In order to support the multiple single fields, Mongo database uses the user-defined indexes, known as compound indexes. Mongo database limits the compound index fields to a maximum of <code>31<\/code><\/li>\n<li><strong>Multi-key Index<\/strong>: This index is used for indexing the field containing an array data i.e. mongo database will create an index for every value in an array<\/li>\n<li><strong>Geospatial Index<\/strong>: This index is used on the 2D indexes and 2D spherical indexes<\/li>\n<li><strong>Text Index<\/strong>: This index is used to search the data string in a Mongo collection<\/li>\n<li><strong>Hashed Index<\/strong>: This index is used to give the hash-based indexes and supports the hash-based sharding<\/li>\n<\/ul>\n<h4>1.3.2 How to create an Index in the Mongo database?<\/h4>\n<p>The below query syntax shows how to create an index in a Mongo collection.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p><span style=\"text-decoration: underline;\"><em>Query Syntax<\/em><\/span><\/p>\n<pre class=\"brush:bash;wrap-lines:false;\">&gt; db.collection_name.createIndex( { field_name: &lt;sorting_value&gt; } )\r\n<\/pre>\n<p>Where:<\/p>\n<ul>\n<li>The <strong>field_name<\/strong> is the attribute name on which the index is created<\/li>\n<li>The <strong>sorting_value<\/strong> is the value through which the sorting order is defined i.e. <code>1<\/code> for ascending order and <code>-1<\/code> for descending order<\/li>\n<\/ul>\n<h2>2. MongoDB Indexing Example<\/h2>\n<p>In this tutorial, we will learn how to handle the <em>single field index<\/em> provided by the Mongo database. But before moving further with the tutorial, we will need to create the sample collection. The following script creates a database called <code>warehouse<\/code> with a collection as <code>editors<\/code>. Open the Mongo terminal and execute the script.<\/p>\n<pre class=\"brush:bash;wrap-lines:false;\">&gt; use warehouse\r\n\r\n&gt; db.editors.insertMany( [\r\n\t{ \"_id\" : \"101\", \"name\" : \"Daniel Atlas\", \"age\": \"26\" }, \r\n\t{ \"_id\" : \"102\", \"name\" : \"Charlotte Neil\", \"age\": \"30\" },\r\n\t{ \"_id\" : \"103\", \"name\" : \"James Breen\", \"age\": \"32\" },\r\n\t{ \"_id\" : \"104\", \"name\" : \"John Gordon\", \"age\": \"24\" },\r\n\t{ \"_id\" : \"105\", \"name\" : \"Rick Ford\", \"age\": \"21\" },\r\n\t{ \"_id\" : \"106\", \"name\" : \"Susan Dixit\", \"age\": \"34\" },\r\n\t{ \"_id\" : \"107\", \"name\" : \"John Snow\", \"age\": \"31\" },\r\n\t{ \"_id\" : \"108\", \"name\" : \"Arya Stark\", \"age\": \"30\" },\r\n\t{ \"_id\" : \"109\", \"name\" : \"Smith William\", \"age\": \"27\" },\r\n\t{ \"_id\" : \"110\", \"name\" : \"John Daniel\", \"age\": \"29\" }\r\n] )\r\n\r\n&gt; db.editors.find().pretty()\r\n<\/pre>\n<p>If everything goes well, the database and the collection will be shown in the Mongo Workbench.<\/p>\n<p><figure id=\"attachment_55691\" aria-describedby=\"caption-attachment-55691\" style=\"width: 849px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/02\/mongodb-index-project-guide-1.jpg\"><img decoding=\"async\" class=\"wp-image-55691 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/02\/mongodb-index-project-guide-1.jpg\" alt=\"Fig. 2: Database &amp;amp; Collection Creation\" width=\"849\" height=\"341\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/02\/mongodb-index-project-guide-1.jpg 849w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/02\/mongodb-index-project-guide-1-300x120.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/02\/mongodb-index-project-guide-1-768x308.jpg 768w\" sizes=\"(max-width: 849px) 100vw, 849px\" \/><\/a><figcaption id=\"caption-attachment-55691\" class=\"wp-caption-text\">Fig. 2: Database &amp; Collection Creation<\/figcaption><\/figure><\/p>\n<h3>2.1 Single Field Index in the Mongo database<\/h3>\n<p>In the Mongo universe, the database developers can create the ascending or the descending order of index on a single field in a collection. Developers can create a single key index as below and here is what the sample command will look like.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Command<\/em><\/span><\/p>\n<pre class=\"brush:bash;wrap-lines:false;\">&gt; db.editors.createIndex( { \"name\": 1 } )\r\n<\/pre>\n<p>Where:<\/p>\n<ul>\n<li><code>name<\/code> is the attribute name on which the index is created in a collection<\/li>\n<li><code>1<\/code> is the value of the sorting order<\/li>\n<\/ul>\n<p>This command will create an index based on the <code>name<\/code> attribute of the document. The <code>1<\/code> parameter indicates that the <code>name<\/code> field values should be sorted in an ascending order. Do <em>remember<\/em>, this is different from the default <code>_id<\/code> field and the Mongo documents will now be sorted as per the <code>name<\/code> field and not the <code>_id<\/code> field.<\/p>\n<p><figure id=\"attachment_55692\" aria-describedby=\"caption-attachment-55692\" style=\"width: 849px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/02\/mongodb-index-project-guide-2.jpg\"><img decoding=\"async\" class=\"wp-image-55692 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/02\/mongodb-index-project-guide-2.jpg\" alt=\"Fig. 3: Creating the Index in the Mongo database\" width=\"849\" height=\"62\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/02\/mongodb-index-project-guide-2.jpg 849w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/02\/mongodb-index-project-guide-2-300x22.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/02\/mongodb-index-project-guide-2-768x56.jpg 768w\" sizes=\"(max-width: 849px) 100vw, 849px\" \/><\/a><figcaption id=\"caption-attachment-55692\" class=\"wp-caption-text\">Fig. 3: Creating the Index in the Mongo database<\/figcaption><\/figure><\/p>\n<p>Here if developers search the document based on the <em>name<\/em>, the search operation will be faster as the indexing mechanism will be used for this search. Thus, <strong>indexing<\/strong> is <em>important<\/em> to create the index on the field that will be frequently searched in a collection.<\/p>\n<h4>2.1.1 Finding the indexes in a Mongo collection<\/h4>\n<p>Developers can use the <code>getIndexes()<\/code> method to find all the indexes created on a collection and here is what the sample command will look like.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Command<\/em><\/span><\/p>\n<pre class=\"brush:bash;wrap-lines:false;\">&gt; db.editors.getIndexes()\r\n<\/pre>\n<p>This command displays the indexes that are available in a particular collection. Here, the default index is created on the <code>_id<\/code> field and the user index will be on the <code>name<\/code> field.<\/p>\n<p><figure id=\"attachment_55693\" aria-describedby=\"caption-attachment-55693\" style=\"width: 849px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/02\/mongodb-index-project-guide-3.jpg\"><img decoding=\"async\" class=\"wp-image-55693 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/02\/mongodb-index-project-guide-3.jpg\" alt=\"Fig. 4: Finding the indexes in a Mongo collection\" width=\"849\" height=\"175\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/02\/mongodb-index-project-guide-3.jpg 849w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/02\/mongodb-index-project-guide-3-300x62.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/02\/mongodb-index-project-guide-3-768x158.jpg 768w\" sizes=\"(max-width: 849px) 100vw, 849px\" \/><\/a><figcaption id=\"caption-attachment-55693\" class=\"wp-caption-text\">Fig. 4: Finding the indexes in a Mongo collection<\/figcaption><\/figure><\/p>\n<h4>2.1.2 Dropping the indexes in a Mongo collection<\/h4>\n<p>Developers can either drop a particular index or all the indexes in a collection. In order to drop a particular index, the following sample command is used.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Command<\/em><\/span><\/p>\n<pre class=\"brush:bash;wrap-lines:false;\">&gt; db.editors.dropIndex( { name: 1 } )\r\n<\/pre>\n<p>Where:<\/p>\n<ul>\n<li><code>name<\/code> is an input argument that works as the <em>index_name<\/em><\/li>\n<\/ul>\n<p>This command displays the information about the existing indexes and the <code>\"ok\" : 1<\/code> output means the command is executed successfully.<\/p>\n<p><figure id=\"attachment_55694\" aria-describedby=\"caption-attachment-55694\" style=\"width: 849px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/02\/mongodb-index-project-guide-4.jpg\"><img decoding=\"async\" class=\"wp-image-55694 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/02\/mongodb-index-project-guide-4.jpg\" alt=\"Fig. 5: Dropping a specific index in a Mongo collection\" width=\"849\" height=\"55\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/02\/mongodb-index-project-guide-4.jpg 849w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/02\/mongodb-index-project-guide-4-300x19.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/02\/mongodb-index-project-guide-4-768x50.jpg 768w\" sizes=\"(max-width: 849px) 100vw, 849px\" \/><\/a><figcaption id=\"caption-attachment-55694\" class=\"wp-caption-text\">Fig. 5: Dropping a specific index in a Mongo collection<\/figcaption><\/figure><\/p>\n<p>In case, developers wish to drop all the indexes of a collection, they can use the <code>dropIndexes()<\/code> method and here is what the query syntax will look like.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Syntax<\/em><\/span><\/p>\n<pre class=\"brush:bash;wrap-lines:false;\">&gt; db.collection_name.dropIndexes()\r\n<\/pre>\n<p><figure id=\"attachment_55695\" aria-describedby=\"caption-attachment-55695\" style=\"width: 849px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/02\/mongodb-index-project-guide-5.jpg\"><img decoding=\"async\" class=\"wp-image-55695 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/02\/mongodb-index-project-guide-5.jpg\" alt=\"Fig. 6: Dropping all indexes in a Mongo collection\" width=\"849\" height=\"74\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/02\/mongodb-index-project-guide-5.jpg 849w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/02\/mongodb-index-project-guide-5-300x26.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/02\/mongodb-index-project-guide-5-768x67.jpg 768w\" sizes=\"(max-width: 849px) 100vw, 849px\" \/><\/a><figcaption id=\"caption-attachment-55695\" class=\"wp-caption-text\">Fig. 6: Dropping all indexes in a Mongo collection<\/figcaption><\/figure><\/p>\n<p>Do <em>remember<\/em>, using this command a developer can only drop the indexes that are created by a developer, but they cannot drop the default index created on the <code>_id<\/code> field. That\u2019s all for this post. Happy Learning!!<\/p>\n<h2>3. Conclusion<\/h2>\n<p>In this tutorial, we learned about the indexes in the Mongo database. Developers can download the sample commands in the <a href=\"#projectDownload\">Downloads<\/a> section.<\/p>\n<h2><a name=\"projectDownload\"><\/a>4. Download the Eclipse Project<\/h2>\n<p>This was an example of <em>indexing<\/em> in the Mongo database.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here: <a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/02\/MongoDbIndexing.zip\" target=\"_blank\" rel=\"noopener\"><strong>MongoDbIndexing<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Hello readers, in Mongo database, an index is a data structure that holds the specific data of the documents. In this tutorial, we will understand the Mongo database indexing to improve the performance of the search query. 1. Introduction If you have installed the MongoDB application (version 3.6) on Windows or Ubuntu operating system and &hellip;<\/p>\n","protected":false},"author":119,"featured_media":36154,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1447],"tags":[1704,1194],"class_list":["post-55690","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-mongodb","tag-indexing","tag-mongodb"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>MongoDB Indexing Example - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"Hello readers, in this tutorial, we will understand the Mongo database indexing to improve the performance of the search query\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-indexing-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"MongoDB Indexing Example - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"Hello readers, in this tutorial, we will understand the Mongo database indexing to improve the performance of the search query\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-indexing-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2018-02-27T13:00:36+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/mongodb-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Yatin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Yatin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-indexing-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-indexing-example\/\"},\"author\":{\"name\":\"Yatin\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/9874407a37b028e8be3276e2b5960d13\"},\"headline\":\"MongoDB Indexing Example\",\"datePublished\":\"2018-02-27T13:00:36+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-indexing-example\/\"},\"wordCount\":1167,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-indexing-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/mongodb-logo.jpg\",\"keywords\":[\"Indexing\",\"MongoDb\"],\"articleSection\":[\"MongoDB\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-indexing-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-indexing-example\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-indexing-example\/\",\"name\":\"MongoDB Indexing Example - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-indexing-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-indexing-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/mongodb-logo.jpg\",\"datePublished\":\"2018-02-27T13:00:36+00:00\",\"description\":\"Hello readers, in this tutorial, we will understand the Mongo database indexing to improve the performance of the search query\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-indexing-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-indexing-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-indexing-example\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/mongodb-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/mongodb-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-indexing-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Software Development\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/software-development\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"MongoDB\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/software-development\/mongodb\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"MongoDB Indexing Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/9874407a37b028e8be3276e2b5960d13\",\"name\":\"Yatin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2023\/09\/cropped-Yatin-Batra_avatar_1515758148-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2023\/09\/cropped-Yatin-Batra_avatar_1515758148-96x96.jpg\",\"caption\":\"Yatin\"},\"description\":\"An experience full-stack engineer well versed with Core Java, Spring\/Springboot, MVC, Security, AOP, Frontend (Angular &amp; React), and cloud technologies (such as AWS, GCP, Jenkins, Docker, K8).\",\"sameAs\":[\"https:\/\/www.javacodegeeks.com\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/yatin-batra\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"MongoDB Indexing Example - Java Code Geeks","description":"Hello readers, in this tutorial, we will understand the Mongo database indexing to improve the performance of the search query","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-indexing-example\/","og_locale":"en_US","og_type":"article","og_title":"MongoDB Indexing Example - Java Code Geeks","og_description":"Hello readers, in this tutorial, we will understand the Mongo database indexing to improve the performance of the search query","og_url":"https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-indexing-example\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2018-02-27T13:00:36+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/mongodb-logo.jpg","type":"image\/jpeg"}],"author":"Yatin","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Yatin","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-indexing-example\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-indexing-example\/"},"author":{"name":"Yatin","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/9874407a37b028e8be3276e2b5960d13"},"headline":"MongoDB Indexing Example","datePublished":"2018-02-27T13:00:36+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-indexing-example\/"},"wordCount":1167,"commentCount":0,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-indexing-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/mongodb-logo.jpg","keywords":["Indexing","MongoDb"],"articleSection":["MongoDB"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-indexing-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-indexing-example\/","url":"https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-indexing-example\/","name":"MongoDB Indexing Example - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-indexing-example\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-indexing-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/mongodb-logo.jpg","datePublished":"2018-02-27T13:00:36+00:00","description":"Hello readers, in this tutorial, we will understand the Mongo database indexing to improve the performance of the search query","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-indexing-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-indexing-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-indexing-example\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/mongodb-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/mongodb-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-indexing-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Software Development","item":"https:\/\/examples.javacodegeeks.com\/category\/software-development\/"},{"@type":"ListItem","position":3,"name":"MongoDB","item":"https:\/\/examples.javacodegeeks.com\/category\/software-development\/mongodb\/"},{"@type":"ListItem","position":4,"name":"MongoDB Indexing Example"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/9874407a37b028e8be3276e2b5960d13","name":"Yatin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2023\/09\/cropped-Yatin-Batra_avatar_1515758148-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2023\/09\/cropped-Yatin-Batra_avatar_1515758148-96x96.jpg","caption":"Yatin"},"description":"An experience full-stack engineer well versed with Core Java, Spring\/Springboot, MVC, Security, AOP, Frontend (Angular &amp; React), and cloud technologies (such as AWS, GCP, Jenkins, Docker, K8).","sameAs":["https:\/\/www.javacodegeeks.com"],"url":"https:\/\/examples.javacodegeeks.com\/author\/yatin-batra\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/55690","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/119"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=55690"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/55690\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/36154"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=55690"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=55690"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=55690"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}