<br />
<b>Warning</b>:  Undefined array key "global_protection_id" in <b>/home/wikitechy/public_html/interview-questions/wp-content/plugins/content-protector/inc/class-ps-rest-handler.php</b> on line <b>51</b><br />
{"id":4068,"date":"2022-04-04T05:50:34","date_gmt":"2022-04-04T05:50:34","guid":{"rendered":"https:\/\/www.wikitechy.com\/interview-questions\/?p=4068"},"modified":"2022-04-04T05:50:34","modified_gmt":"2022-04-04T05:50:34","slug":"what-is-the-use-of-index-in-mongodb","status":"publish","type":"post","link":"https:\/\/www.wikitechy.com\/interview-questions\/mongodb\/what-is-the-use-of-index-in-mongodb\/","title":{"rendered":"What is the use of Index in Mongodb ?"},"content":{"rendered":"<ul>\n<li style=\"text-align: justify;\">MongoDB is one of the leading NoSQL database. It is written in C++ Program.<\/li>\n<li style=\"text-align: justify;\">It provides high performance and availability and high scalable.<\/li>\n<li style=\"text-align: justify;\">Indexing in MongoDB is used to make query processing more efficient.<\/li>\n<li style=\"text-align: justify;\">The MongoDB scan every document in the collection and retrieve only those documents that match the query, where there is no indexing.<\/li>\n<li style=\"text-align: justify;\">Indexes are special data structures that stores some information related to the documents such that it becomes easy for MongoDB to find the right data file.<\/li>\n<li style=\"text-align: justify;\">Indexes are ordered by the value of the field specified in the index.<\/li>\n<\/ul>\n<h5 id=\"index-creating\"><strong>Index Creating :<\/strong><\/h5>\n<ul>\n<li>\u00a0createIndex() is a method that allows user to create an index.<\/li>\n<\/ul>\n<h5 id=\"syntax\"><strong>Syntax :<\/strong><\/h5>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone size-full wp-image-4069\" src=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/04\/how-mongodb-indexes-works.png\" alt=\"\" width=\"876\" height=\"148\" srcset=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/04\/how-mongodb-indexes-works.png 876w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/04\/how-mongodb-indexes-works-300x51.png 300w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/04\/how-mongodb-indexes-works-768x130.png 768w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/04\/how-mongodb-indexes-works-390x66.png 390w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/04\/how-mongodb-indexes-works-820x139.png 820w\" sizes=\"(max-width: 876px) 100vw, 876px\" \/><\/p>\n<p>For Example,<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-markup code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-markup code-embed-code\">db.mycol.createIndex({\u201cage\u201d:1})<br\/>{<br\/>\u201ccreatedCollectionAutomatically\u201d : false,<br\/>\u201cnumIndexesBefore\u201d : 1,<br\/>\u201cnumIndexesAfter\u201d : 2,<br\/>\u201cok\u201d : 1<br\/>} <\/code><\/pre> <\/div>\n<ul>\n<li>In createIndex() method, there are five types of parameters:<\/li>\n<\/ul>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\n<li>background (Boolean)<\/li>\n<li>unique (Boolean)<\/li>\n<li>name (string)<\/li>\n<li>sparse (Boolean)<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<h5 id=\"index-for-drop\"><strong>Index for Drop :<\/strong><\/h5>\n<ul>\n<li>dropIndex() is a method that allows users to drop an index.<\/li>\n<li>This method can delete only one index at a time.<\/li>\n<li>MongoDB provides the dropIndexes() method that takes multiple indexes as its parameters.<\/li>\n<\/ul>\n<h5 id=\"syntax-2\">Syntax :<\/h5>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-4070\" src=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/04\/indexing-in-mongodb.png\" alt=\"\" width=\"845\" height=\"159\" srcset=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/04\/indexing-in-mongodb.png 845w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/04\/indexing-in-mongodb-300x56.png 300w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/04\/indexing-in-mongodb-768x145.png 768w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/04\/indexing-in-mongodb-390x73.png 390w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/04\/indexing-in-mongodb-820x154.png 820w\" sizes=\"(max-width: 845px) 100vw, 845px\" \/><\/p>\n<h5 id=\"get-description-of-all-indexes\"><strong>Get description of all indexes :<\/strong><\/h5>\n<ul>\n<li>It will retrieve all the description of the indexes created within the collection.<\/li>\n<\/ul>\n<h5 id=\"syntax-3\"><strong>Syntax :<\/strong><\/h5>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-4071\" src=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/04\/mongodb-indexing.png\" alt=\"\" width=\"834\" height=\"155\" srcset=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/04\/mongodb-indexing.png 834w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/04\/mongodb-indexing-300x56.png 300w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/04\/mongodb-indexing-768x143.png 768w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/04\/mongodb-indexing-390x72.png 390w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/04\/mongodb-indexing-820x152.png 820w\" sizes=\"(max-width: 834px) 100vw, 834px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>MongoDB is one of the leading NoSQL database. It is written in C++ Program. It provides high performance and availability and high scalable. Indexing in MongoDB is used to make query processing more efficient. The MongoDB scan every document in the collection and retrieve only those documents that match the query, where there is no [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"passster_activate_protection":false,"passster_protect_child_pages":"","passster_protection_type":"password","passster_password":"","passster_activate_overwrite_defaults":"","passster_headline":"","passster_instruction":"","passster_placeholder":"","passster_button":"","passster_id":"","passster_activate_misc_settings":"","passster_redirect_url":"","passster_hide":"no","passster_area_shortcode":"","gtb_hide_title":false,"gtb_wrap_title":false,"gtb_class_title":"","gtb_remove_headerfooter":false,"footnotes":""},"categories":[16831],"tags":[16850,16854,16852,16845,16848,16847,16849,16846,16853,16844,16856,16851,16855],"class_list":["post-4068","post","type-post","status-publish","format-standard","hentry","category-mongodb","tag-compound-index-mongodb","tag-does-mongodb-have-indexes","tag-how-does-index-work-in-mongodb","tag-how-indexing-works-in-mongodb","tag-indexing-in-mongodb","tag-indexing-in-mongodb-example","tag-mongodb-indexing-best-practices","tag-types-of-index-in-mongodb","tag-what-is-compound-index-in-mongodb","tag-what-is-indexes-in-mongodb","tag-what-is-text-index-in-mongodb","tag-what-is-the-use-of-index-in-mongodb","tag-why-create-index-in-mongodb"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>What is the use of Index in Mongodb ? - Mongodb Interview Questions<\/title>\n<meta name=\"description\" content=\"What is the use of Index in Mongodb ? - In C++ program MongoDB\u00a0is one of leading NoSQL database written.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wikitechy.com\/interview-questions\/mongodb\/what-is-the-use-of-index-in-mongodb\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"What is the use of Index in Mongodb ? - Mongodb Interview Questions\" \/>\n<meta property=\"og:description\" content=\"What is the use of Index in Mongodb ? - In C++ program MongoDB\u00a0is one of leading NoSQL database written.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wikitechy.com\/interview-questions\/mongodb\/what-is-the-use-of-index-in-mongodb\/\" \/>\n<meta property=\"og:site_name\" content=\"Wikitechy\" \/>\n<meta property=\"article:published_time\" content=\"2022-04-04T05:50:34+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/04\/how-mongodb-indexes-works.png\" \/>\n<meta name=\"author\" content=\"webmaster\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"webmaster\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/mongodb\/what-is-the-use-of-index-in-mongodb\/\",\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/mongodb\/what-is-the-use-of-index-in-mongodb\/\",\"name\":\"What is the use of Index in Mongodb ? - Mongodb Interview Questions\",\"isPartOf\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/mongodb\/what-is-the-use-of-index-in-mongodb\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/mongodb\/what-is-the-use-of-index-in-mongodb\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/04\/how-mongodb-indexes-works.png\",\"datePublished\":\"2022-04-04T05:50:34+00:00\",\"dateModified\":\"2022-04-04T05:50:34+00:00\",\"author\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/f785ba3ecc599133e65ab6138042a3e4\"},\"description\":\"What is the use of Index in Mongodb ? - In C++ program MongoDB\u00a0is one of leading NoSQL database written.\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wikitechy.com\/interview-questions\/mongodb\/what-is-the-use-of-index-in-mongodb\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/mongodb\/what-is-the-use-of-index-in-mongodb\/#primaryimage\",\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/04\/how-mongodb-indexes-works.png\",\"contentUrl\":\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/04\/how-mongodb-indexes-works.png\",\"width\":876,\"height\":148},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#website\",\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/\",\"name\":\"Wikitechy\",\"description\":\"Interview Questions\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wikitechy.com\/interview-questions\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/f785ba3ecc599133e65ab6138042a3e4\",\"name\":\"webmaster\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/155b77fd8cdda3d0913fcb7e7ee63543b0c345d2d8f6dcebda5b0583ab61f967?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/155b77fd8cdda3d0913fcb7e7ee63543b0c345d2d8f6dcebda5b0583ab61f967?s=96&d=mm&r=g\",\"caption\":\"webmaster\"},\"sameAs\":[\"https:\/\/www.wikitechy.com\/interview-questions\"],\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/author\/webmaster\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"What is the use of Index in Mongodb ? - Mongodb Interview Questions","description":"What is the use of Index in Mongodb ? - In C++ program MongoDB\u00a0is one of leading NoSQL database written.","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:\/\/www.wikitechy.com\/interview-questions\/mongodb\/what-is-the-use-of-index-in-mongodb\/","og_locale":"en_US","og_type":"article","og_title":"What is the use of Index in Mongodb ? - Mongodb Interview Questions","og_description":"What is the use of Index in Mongodb ? - In C++ program MongoDB\u00a0is one of leading NoSQL database written.","og_url":"https:\/\/www.wikitechy.com\/interview-questions\/mongodb\/what-is-the-use-of-index-in-mongodb\/","og_site_name":"Wikitechy","article_published_time":"2022-04-04T05:50:34+00:00","og_image":[{"url":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/04\/how-mongodb-indexes-works.png"}],"author":"webmaster","twitter_card":"summary_large_image","twitter_misc":{"Written by":"webmaster","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wikitechy.com\/interview-questions\/mongodb\/what-is-the-use-of-index-in-mongodb\/","url":"https:\/\/www.wikitechy.com\/interview-questions\/mongodb\/what-is-the-use-of-index-in-mongodb\/","name":"What is the use of Index in Mongodb ? - Mongodb Interview Questions","isPartOf":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/mongodb\/what-is-the-use-of-index-in-mongodb\/#primaryimage"},"image":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/mongodb\/what-is-the-use-of-index-in-mongodb\/#primaryimage"},"thumbnailUrl":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/04\/how-mongodb-indexes-works.png","datePublished":"2022-04-04T05:50:34+00:00","dateModified":"2022-04-04T05:50:34+00:00","author":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/f785ba3ecc599133e65ab6138042a3e4"},"description":"What is the use of Index in Mongodb ? - In C++ program MongoDB\u00a0is one of leading NoSQL database written.","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wikitechy.com\/interview-questions\/mongodb\/what-is-the-use-of-index-in-mongodb\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.wikitechy.com\/interview-questions\/mongodb\/what-is-the-use-of-index-in-mongodb\/#primaryimage","url":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/04\/how-mongodb-indexes-works.png","contentUrl":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/04\/how-mongodb-indexes-works.png","width":876,"height":148},{"@type":"WebSite","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#website","url":"https:\/\/www.wikitechy.com\/interview-questions\/","name":"Wikitechy","description":"Interview Questions","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wikitechy.com\/interview-questions\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/f785ba3ecc599133e65ab6138042a3e4","name":"webmaster","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/155b77fd8cdda3d0913fcb7e7ee63543b0c345d2d8f6dcebda5b0583ab61f967?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/155b77fd8cdda3d0913fcb7e7ee63543b0c345d2d8f6dcebda5b0583ab61f967?s=96&d=mm&r=g","caption":"webmaster"},"sameAs":["https:\/\/www.wikitechy.com\/interview-questions"],"url":"https:\/\/www.wikitechy.com\/interview-questions\/author\/webmaster\/"}]}},"_links":{"self":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/4068","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/comments?post=4068"}],"version-history":[{"count":1,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/4068\/revisions"}],"predecessor-version":[{"id":4072,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/4068\/revisions\/4072"}],"wp:attachment":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/media?parent=4068"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/categories?post=4068"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/tags?post=4068"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}