{"id":11408,"date":"2014-01-26T19:00:36","date_gmt":"2014-01-26T13:30:36","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=11408"},"modified":"2014-01-26T19:00:36","modified_gmt":"2014-01-26T13:30:36","slug":"capped-collections-in-mongodb","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/capped-collections-in-mongodb\/","title":{"rendered":"Capped Collections In Mongodb"},"content":{"rendered":"<p>We can create collections in mongoDb on which we can apply size limit. These special type of collections are called <strong>Capped Collections<\/strong>. These are a kind of circular queues, in which if allocated size limit is reached, it makes space for new documents by overwriting the oldest documents in the collection. <\/p>\n<p><strong>How to create Capped Collections:<\/strong><br \/>\n<code>db.createCollection(nameOfCollection, {capped: Boolean, autoIndexId: Boolean, size: Number, max : Number})<\/code><br \/>\nHere the parameters specify:<\/p>\n<ul>\n<li>nameOfCollection: the capped collection name<\/li>\n<li>&#8220;capped&#8221; option : set to true in case to create a capped collection<\/li>\n<li>&#8220;size&#8221; option: specify the size limit for the collection in bytes(mandatory in case of capped collection)\n<li>&#8220;max&#8221; option: specify the limit on maximum number of documents allowed in the collection(size option is given preference over max option)<\/li>\n<li>&#8220;autoIndexId&#8221; option: set to false in case of capped collections to disable the automatic index creation<\/li>\n<\/ul>\n<p> For example lets create a capped collection named &#8220;demo&#8221;.<br \/>\n<img decoding=\"async\" src=\"\/blog\/wp-ttn-blog\/uploads\/2014\/01\/Screenshot-from-2014-01-26-173904.png\" alt=\"create capped collection\" \/><\/p>\n<p>Here we have put size limit to 500 bytes and maximum number of documents to 3. Now lets insert some documents in this collection.<br \/>\n<img decoding=\"async\" src=\"\/blog\/wp-ttn-blog\/uploads\/2014\/01\/Screenshot-from-2014-01-26-174108.png\" alt=\"Blog image\" \/><\/p>\n<p>Now, the maximum size limit has reached and if we try to add more documents, the old documents get over ridden by new one.<br \/>\n<img decoding=\"async\" src=\"\/blog\/wp-ttn-blog\/uploads\/2014\/01\/Screenshot-from-2014-01-26-174202.png\" alt=\"Blog image\" \/><\/p>\n<p><strong>Note:<\/strong> <code>db.collection.isCapped()<\/code> command is used to check if a collection is a Capped collection or not.<\/p>\n<p><strong>Advantages of Capped Collections:<\/strong><br \/>\n1. Queries do not need an index to return documents in insertion order due to which it provide higher insertion throughput.<\/p>\n<p>2. Capped collections only allow updates that fit the original document size, which ensures a document does not change its location on disk.<\/p>\n<p>3. Useful for keeping log files.<\/p>\n<p><strong>Disadvantages of Capped Collections:<\/strong><br \/>\n1. If the update operation increases the original size of the capped collection, the update operation fails.<\/p>\n<p>2. We cannot delete documents from a capped collection. To remove all records from a capped collection, use the <code>{ emptycapped: nameOfCollection }<\/code> command.<\/p>\n<p>3. We cannot shard a capped collection.<\/p>\n<p>So we can make a choice whether to use capped collection according to our use case.<\/p>\n<p>Hope this will help \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We can create collections in mongoDb on which we can apply size limit. These special type of collections are called Capped Collections. These are a kind of circular queues, in which if allocated size limit is reached, it makes space for new documents by overwriting the oldest documents in the collection. How to create Capped [&hellip;]<\/p>\n","protected":false},"author":65,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":21,"footnotes":""},"categories":[1],"tags":[1270,4846],"class_list":["post-11408","post","type-post","status-publish","format-standard","hentry","category-technology","tag-capped-collection","tag-mongodb"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.0.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"We can create collections in mongoDb on which we can apply size limit. These special type of collections are called Capped Collections. These are a kind of circular queues, in which if allocated size limit is reached, it makes space for new documents by overwriting the oldest documents in the collection. How to create Capped\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Sakshi Tyagi\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/www.tothenew.com\/blog\/capped-collections-in-mongodb\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.0.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"TO THE NEW BLOG\" \/>\n\t\t<meta property=\"og:type\" content=\"blog\" \/>\n\t\t<meta property=\"og:title\" content=\"Capped Collections In Mongodb | TO THE NEW Blog\" \/>\n\t\t<meta property=\"og:description\" content=\"We can create collections in mongoDb on which we can apply size limit. These special type of collections are called Capped Collections. These are a kind of circular queues, in which if allocated size limit is reached, it makes space for new documents by overwriting the oldest documents in the collection. How to create Capped\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.tothenew.com\/blog\/capped-collections-in-mongodb\/\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:site\" content=\"@tothenew\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Capped Collections In Mongodb | TO THE NEW Blog\" \/>\n\t\t<meta name=\"twitter:description\" content=\"We can create collections in mongoDb on which we can apply size limit. These special type of collections are called Capped Collections. These are a kind of circular queues, in which if allocated size limit is reached, it makes space for new documents by overwriting the oldest documents in the collection. How to create Capped\" \/>\n\t\t<meta name=\"twitter:image\" content=\"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/capped-collections-in-mongodb\\\/#article\",\"name\":\"Capped Collections In Mongodb | TO THE NEW Blog\",\"headline\":\"Capped Collections In Mongodb\",\"author\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/sakshi\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"\\\/blog\\\/wp-ttn-blog\\\/uploads\\\/2014\\\/01\\\/Screenshot-from-2014-01-26-173904.png\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/capped-collections-in-mongodb\\\/#articleImage\"},\"datePublished\":\"2014-01-26T19:00:36+05:30\",\"dateModified\":\"2014-01-26T19:00:36+05:30\",\"inLanguage\":\"en-US\",\"commentCount\":2,\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/capped-collections-in-mongodb\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/capped-collections-in-mongodb\\\/#webpage\"},\"articleSection\":\"Technology, capped collection, MongoDB\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/capped-collections-in-mongodb\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.tothenew.com\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/technology\\\/#listItem\",\"name\":\"Technology\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/technology\\\/#listItem\",\"position\":2,\"name\":\"Technology\",\"item\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/technology\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/capped-collections-in-mongodb\\\/#listItem\",\"name\":\"Capped Collections In Mongodb\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/capped-collections-in-mongodb\\\/#listItem\",\"position\":3,\"name\":\"Capped Collections In Mongodb\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/technology\\\/#listItem\",\"name\":\"Technology\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\",\"name\":\"TO THE NEW Blog\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/sakshi\\\/#author\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/sakshi\\\/\",\"name\":\"Sakshi Tyagi\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/capped-collections-in-mongodb\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a42c6deb088e18815dfcfed629c77b032d17bf973881421880b9c5e4ba713739?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Sakshi Tyagi\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/capped-collections-in-mongodb\\\/#webpage\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/capped-collections-in-mongodb\\\/\",\"name\":\"Capped Collections In Mongodb | TO THE NEW Blog\",\"description\":\"We can create collections in mongoDb on which we can apply size limit. These special type of collections are called Capped Collections. These are a kind of circular queues, in which if allocated size limit is reached, it makes space for new documents by overwriting the oldest documents in the collection. How to create Capped\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/capped-collections-in-mongodb\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/sakshi\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/sakshi\\\/#author\"},\"datePublished\":\"2014-01-26T19:00:36+05:30\",\"dateModified\":\"2014-01-26T19:00:36+05:30\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/\",\"name\":\"TO THE NEW Blog\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Capped Collections In Mongodb | TO THE NEW Blog","description":"We can create collections in mongoDb on which we can apply size limit. These special type of collections are called Capped Collections. These are a kind of circular queues, in which if allocated size limit is reached, it makes space for new documents by overwriting the oldest documents in the collection. How to create Capped","canonical_url":"https:\/\/www.tothenew.com\/blog\/capped-collections-in-mongodb\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.tothenew.com\/blog\/capped-collections-in-mongodb\/#article","name":"Capped Collections In Mongodb | TO THE NEW Blog","headline":"Capped Collections In Mongodb","author":{"@id":"https:\/\/www.tothenew.com\/blog\/author\/sakshi\/#author"},"publisher":{"@id":"https:\/\/www.tothenew.com\/blog\/#organization"},"image":{"@type":"ImageObject","url":"\/blog\/wp-ttn-blog\/uploads\/2014\/01\/Screenshot-from-2014-01-26-173904.png","@id":"https:\/\/www.tothenew.com\/blog\/capped-collections-in-mongodb\/#articleImage"},"datePublished":"2014-01-26T19:00:36+05:30","dateModified":"2014-01-26T19:00:36+05:30","inLanguage":"en-US","commentCount":2,"mainEntityOfPage":{"@id":"https:\/\/www.tothenew.com\/blog\/capped-collections-in-mongodb\/#webpage"},"isPartOf":{"@id":"https:\/\/www.tothenew.com\/blog\/capped-collections-in-mongodb\/#webpage"},"articleSection":"Technology, capped collection, MongoDB"},{"@type":"BreadcrumbList","@id":"https:\/\/www.tothenew.com\/blog\/capped-collections-in-mongodb\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog#listItem","position":1,"name":"Home","item":"https:\/\/www.tothenew.com\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/category\/technology\/#listItem","name":"Technology"}},{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/category\/technology\/#listItem","position":2,"name":"Technology","item":"https:\/\/www.tothenew.com\/blog\/category\/technology\/","nextItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/capped-collections-in-mongodb\/#listItem","name":"Capped Collections In Mongodb"},"previousItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/capped-collections-in-mongodb\/#listItem","position":3,"name":"Capped Collections In Mongodb","previousItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/category\/technology\/#listItem","name":"Technology"}}]},{"@type":"Organization","@id":"https:\/\/www.tothenew.com\/blog\/#organization","name":"TO THE NEW Blog","url":"https:\/\/www.tothenew.com\/blog\/"},{"@type":"Person","@id":"https:\/\/www.tothenew.com\/blog\/author\/sakshi\/#author","url":"https:\/\/www.tothenew.com\/blog\/author\/sakshi\/","name":"Sakshi Tyagi","image":{"@type":"ImageObject","@id":"https:\/\/www.tothenew.com\/blog\/capped-collections-in-mongodb\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/a42c6deb088e18815dfcfed629c77b032d17bf973881421880b9c5e4ba713739?s=96&d=mm&r=g","width":96,"height":96,"caption":"Sakshi Tyagi"}},{"@type":"WebPage","@id":"https:\/\/www.tothenew.com\/blog\/capped-collections-in-mongodb\/#webpage","url":"https:\/\/www.tothenew.com\/blog\/capped-collections-in-mongodb\/","name":"Capped Collections In Mongodb | TO THE NEW Blog","description":"We can create collections in mongoDb on which we can apply size limit. These special type of collections are called Capped Collections. These are a kind of circular queues, in which if allocated size limit is reached, it makes space for new documents by overwriting the oldest documents in the collection. How to create Capped","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/www.tothenew.com\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/www.tothenew.com\/blog\/capped-collections-in-mongodb\/#breadcrumblist"},"author":{"@id":"https:\/\/www.tothenew.com\/blog\/author\/sakshi\/#author"},"creator":{"@id":"https:\/\/www.tothenew.com\/blog\/author\/sakshi\/#author"},"datePublished":"2014-01-26T19:00:36+05:30","dateModified":"2014-01-26T19:00:36+05:30"},{"@type":"WebSite","@id":"https:\/\/www.tothenew.com\/blog\/#website","url":"https:\/\/www.tothenew.com\/blog\/","name":"TO THE NEW Blog","inLanguage":"en-US","publisher":{"@id":"https:\/\/www.tothenew.com\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"TO THE NEW BLOG","og:type":"blog","og:title":"Capped Collections In Mongodb | TO THE NEW Blog","og:description":"We can create collections in mongoDb on which we can apply size limit. These special type of collections are called Capped Collections. These are a kind of circular queues, in which if allocated size limit is reached, it makes space for new documents by overwriting the oldest documents in the collection. How to create Capped","og:url":"https:\/\/www.tothenew.com\/blog\/capped-collections-in-mongodb\/","og:image":"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png","og:image:secure_url":"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png","twitter:card":"summary","twitter:site":"@tothenew","twitter:title":"Capped Collections In Mongodb | TO THE NEW Blog","twitter:description":"We can create collections in mongoDb on which we can apply size limit. These special type of collections are called Capped Collections. These are a kind of circular queues, in which if allocated size limit is reached, it makes space for new documents by overwriting the oldest documents in the collection. How to create Capped","twitter:image":"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png"},"aioseo_meta_data":{"post_id":"11408","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"limit_modified_date":false,"created":"2021-04-29 15:57:32","updated":"2024-02-29 09:27:24","focus_keyword":null,"additional_keywords":null,"truseo_locale":null,"ai":null,"breadcrumb_settings":null,"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.tothenew.com\/blog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.tothenew.com\/blog\/category\/technology\/\" title=\"Technology\">Technology<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tCapped Collections In Mongodb\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/www.tothenew.com\/blog"},{"label":"Technology","link":"https:\/\/www.tothenew.com\/blog\/category\/technology\/"},{"label":"Capped Collections In Mongodb","link":"https:\/\/www.tothenew.com\/blog\/capped-collections-in-mongodb\/"}],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/11408","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/65"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=11408"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/11408\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=11408"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=11408"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=11408"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}