{"id":1524,"date":"2014-12-16T19:21:06","date_gmt":"2014-12-16T19:21:06","guid":{"rendered":"https:\/\/www.couchbase.com\/blog\/?p=1524"},"modified":"2023-06-28T00:42:15","modified_gmt":"2023-06-28T07:42:15","slug":"calculating-average-document-size-documents-stored-couchbase","status":"publish","type":"post","link":"https:\/\/www.couchbase.com\/blog\/calculating-average-document-size-documents-stored-couchbase\/","title":{"rendered":"Calculating average document size of documents stored in Couchbase."},"content":{"rendered":"<p dir=\"ltr\" style=\"line-height: 1.15;margin-top: 0pt;margin-bottom: 0pt\"><span style=\"font-size: 16px;font-family: Arial;color: #000000;background-color: transparent;font-weight: normal;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\">Couchbase offers an unique NoSQL database combining integrated cache and storage technology. Many customers and prospects are using it to store binary data and\/or JSON documents. Often; it is necessary to determine average document size to be able to properly size a production system. See this great set of blogs from Perry to learn more about Couchbase sizing:<\/span><\/p>\n<ul dir=\"ltr\">\n<li style=\"line-height: 1.15;margin-top: 0pt;margin-bottom: 0pt\"><a style=\"text-decoration: none\" href=\"https:\/\/www.couchbase.com\/blog\/how-many-nodes-part-1-introduction-sizing-couchbase-server-20-cluster\/\"><span style=\"font-size: 16px;font-family: Arial;color: #1155cc;background-color: transparent;font-weight: normal;font-style: normal;font-variant: normal;text-decoration: underline;vertical-align: baseline\">https:\/\/www.couchbase.com\/blog\/how-many-nodes-part-1-introduction-sizing-couchbase-server-20-cluster<\/span><\/a><\/li>\n<li style=\"line-height: 1.15;margin-top: 0pt;margin-bottom: 0pt\"><a style=\"text-decoration: none\" href=\"https:\/\/www.couchbase.com\/blog\/how-many-nodes-part-2-sizing-couchbase-server-20-cluster\/\"><span style=\"font-size: 16px;font-family: Arial;color: #1155cc;background-color: transparent;font-weight: normal;font-style: normal;font-variant: normal;text-decoration: underline;vertical-align: baseline\">https:\/\/www.couchbase.com\/blog\/how-many-nodes-part-2-sizing-couchbase-server-20-cluster<\/span><\/a><\/li>\n<\/ul>\n<p dir=\"ltr\" style=\"line-height: 1.15;margin-top: 0pt;margin-bottom: 0pt\"><span style=\"font-size: 16px;font-family: Arial;color: #000000;background-color: transparent;font-weight: normal;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\">This blog entry details a simple way to calculate average document size (for binary data and JSON documents) using views.<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.15;margin-top: 0pt;margin-bottom: 0pt\"><span style=\"font-size: 16px;font-family: Arial;color: #000000;background-color: transparent;font-weight: normal;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\">This is meant to be used in a development or staging system only and <\/span><span style=\"font-size: 16px;font-family: Arial;color: #000000;background-color: transparent;font-weight: bold;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\">not<\/span><span style=\"font-size: 16px;font-family: Arial;color: #000000;background-color: transparent;font-weight: normal;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\"> in a real production system as this will create overhead while indexing every document.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p dir=\"ltr\" style=\"line-height: 1.15;margin-top: 0pt;margin-bottom: 0pt\"><span style=\"font-size: 16px;font-family: Arial;color: #000000;background-color: transparent;font-weight: normal;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\">Views are functions that you write in Javascript and which allow to extract, filter, aggregate and find information for documents stored in Couchbase server.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p dir=\"ltr\" style=\"line-height: 1.15;margin-top: 0pt;margin-bottom: 6pt\"><span style=\"font-size: 16px;font-family: Arial;color: #000000;background-color: transparent;font-weight: normal;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\">First step in creating a view is to provide a <\/span><span style=\"font-size: 16px;font-family: Arial;color: #000000;background-color: transparent;font-weight: bold;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\">map<\/span><span style=\"font-size: 16px;font-family: Arial;color: #000000;background-color: transparent;font-weight: normal;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\"> function which will filter entries for certain information and extract some of the information. The result of a map function is an ordered list of key\/value pairs, called an <\/span><span style=\"font-size: 16px;font-family: Arial;color: #000000;background-color: transparent;font-weight: bold;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\">index<\/span><span style=\"font-size: 16px;font-family: Arial;color: #000000;background-color: transparent;font-weight: normal;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\">. The results of map functions are persisted on to disk by Couchbase server and will be updated incrementally as documents change.<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.15;margin-top: 0pt;margin-bottom: 6pt\"><span style=\"font-size: 16px;font-family: Arial;color: #000000;background-color: transparent;font-weight: normal;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\">Additionally and optionally, it is possible to create a <\/span><span style=\"font-size: 16px;font-family: Arial;color: #000000;background-color: transparent;font-weight: bold;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\">reduce<\/span><span style=\"font-size: 16px;font-family: Arial;color: #000000;background-color: transparent;font-weight: normal;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\"> function which can sum, aggregate, or perform calculations on information.<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.15;margin-top: 0pt;margin-bottom: 6pt\"><span style=\"font-size: 16px;font-family: Arial;color: #000000;background-color: transparent;font-weight: normal;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\">Views are explained in our development guide at:<\/span><br \/>\n<a style=\"text-decoration: none\" href=\"https:\/\/www.couchbase.com\/docs\/couchbase-devguide-2.1.0\/understanding-views.html\"><span style=\"font-size: 16px;font-family: Arial;color: #1155cc;background-color: transparent;font-weight: normal;font-style: normal;font-variant: normal;text-decoration: underline;vertical-align: baseline\">https:\/\/www.couchbase.com\/docs\/couchbase-devguide-2.1.0\/understanding-views.html<\/span><\/a><\/p>\n<p>&nbsp;<\/p>\n<p dir=\"ltr\" style=\"line-height: 1.15;margin-top: 0pt;margin-bottom: 0pt\"><span style=\"font-size: 16px;font-family: Arial;color: #000000;background-color: transparent;font-weight: normal;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\">Now let\u2019s take a look at what it will take to create the view:<\/span><\/p>\n<p>&nbsp;<\/p>\n<p dir=\"ltr\" style=\"line-height: 1.15;margin-top: 0pt;margin-bottom: 0pt\"><span style=\"font-size: 16px;font-family: Arial;color: #000000;background-color: transparent;font-weight: bold;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\">Map<\/span><span style=\"font-size: 16px;font-family: Arial;color: #000000;background-color: transparent;font-weight: normal;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\">: the following code of the map function for the view generates a simple Key Value pair index with the Key being the key for the document and the Value the length of the document:<\/span><\/p>\n<p>&nbsp;<\/p>\n<p dir=\"ltr\" style=\"line-height: 1.15;margin-top: 0pt;margin-bottom: 0pt\"><span style=\"font-size: 16px;font-family: Arial;color: #000000;background-color: transparent;font-weight: normal;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\">function (doc, meta) {<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.15;margin-top: 0pt;margin-bottom: 0pt\"><span style=\"font-size: 16px;font-family: Arial;color: #000000;background-color: transparent;font-weight: normal;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\">\u00a0if (meta.type == &#8220;json&#8221;) {<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.15;margin-top: 0pt;margin-bottom: 0pt\"><span style=\"font-size: 16px;font-family: Arial;color: #000000;background-color: transparent;font-weight: normal;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\">\u00a0\u00a0\u00a0var size = JSON.stringify(doc).length;<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.15;margin-top: 0pt;margin-bottom: 0pt\"><span style=\"font-size: 16px;font-family: Arial;color: #000000;background-color: transparent;font-weight: normal;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\">\u00a0\u00a0\u00a0emit(meta.id, size);<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.15;margin-top: 0pt;margin-bottom: 0pt\"><span style=\"font-size: 16px;font-family: Arial;color: #000000;background-color: transparent;font-weight: normal;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\">\u00a0} <\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.15;margin-top: 0pt;margin-bottom: 0pt\"><span style=\"font-size: 16px;font-family: Arial;color: #000000;background-color: transparent;font-weight: normal;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\">\u00a0if (meta.type == &#8220;base64&#8221;) {<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.15;margin-top: 0pt;margin-bottom: 0pt\"><span style=\"font-size: 16px;font-family: Arial;color: #000000;background-color: transparent;font-weight: normal;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\">\u00a0\u00a0\u00a0var size = decodeBase64(doc).length;<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.15;margin-top: 0pt;margin-bottom: 0pt\"><span style=\"font-size: 16px;font-family: Arial;color: #000000;background-color: transparent;font-weight: normal;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\">\u00a0\u00a0\u00a0emit(meta.id, size); \u00a0\u00a0\u00a0<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.15;margin-top: 0pt;margin-bottom: 0pt\"><span style=\"font-size: 16px;font-family: Arial;color: #000000;background-color: transparent;font-weight: normal;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\">\u00a0}<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.15;margin-top: 0pt;margin-bottom: 0pt\"><span style=\"font-size: 16px;font-family: Arial;color: #000000;background-color: transparent;font-weight: normal;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\">}<\/span><\/p>\n<p>&nbsp;<\/p>\n<p dir=\"ltr\" style=\"line-height: 1.15;margin-top: 0pt;margin-bottom: 0pt\"><span style=\"font-size: 16px;font-family: Arial;color: #000000;background-color: transparent;font-weight: normal;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\">The function works for JSON documents (using JSON.stringify) and Binary documents (using decodeBase64)<\/span><\/p>\n<p>&nbsp;<\/p>\n<p dir=\"ltr\" style=\"line-height: 1.15;margin-top: 0pt;margin-bottom: 0pt\"><span style=\"font-size: 16px;font-family: Arial;color: #000000;background-color: transparent;font-weight: normal;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\">The function could be augmented to be able to calculate average size for specific documents as needed.<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.15;margin-top: 0pt;margin-bottom: 0pt\"><span style=\"font-size: 16px;font-family: Arial;color: #000000;background-color: transparent;font-weight: bold;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\">Reduce<\/span><span style=\"font-size: 16px;font-family: Arial;color: #000000;background-color: transparent;font-weight: normal;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\">: finally, we create a reduce function (Thanks Aaron at Couchbase (<\/span>https:\/\/twitter.com\/apage43)\u00a0<span style=\"font-size: 16px;font-family: Arial;color: #000000;background-color: transparent;font-weight: normal;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\"> for helping create it!) for the view which calculates average document size by aggregating the values and dividing by the number of values. It follows map and reduce construct so looks a little bit complicated at first but will output count, sum and average (the default built-in functions do not provide the average and I wanted to make this function very easy to use).<\/span><\/p>\n<p>&nbsp;<\/p>\n<p dir=\"ltr\" style=\"line-height: 1.15;margin-top: 0pt;margin-bottom: 0pt\"><span style=\"font-size: 16px;font-family: Arial;color: #000000;background-color: transparent;font-weight: normal;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\">function (keys, values, rereduce) {<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.15;margin-top: 0pt;margin-bottom: 0pt\"><span style=\"font-size: 16px;font-family: Arial;color: #000000;background-color: transparent;font-weight: normal;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\">\u00a0if(!rereduce) {<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.15;margin-top: 0pt;margin-bottom: 0pt\"><span style=\"font-size: 16px;font-family: Arial;color: #000000;background-color: transparent;font-weight: normal;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\">\u00a0\u00a0\u00a0var total = 0,<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.15;margin-top: 0pt;margin-bottom: 0pt\"><span style=\"font-size: 16px;font-family: Arial;color: #000000;background-color: transparent;font-weight: normal;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0count = 0;<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.15;margin-top: 0pt;margin-bottom: 0pt\"><span style=\"font-size: 16px;font-family: Arial;color: #000000;background-color: transparent;font-weight: normal;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\">\u00a0\u00a0\u00a0for (v in values) {<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.15;margin-top: 0pt;margin-bottom: 0pt\"><span style=\"font-size: 16px;font-family: Arial;color: #000000;background-color: transparent;font-weight: normal;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\">\u00a0\u00a0\u00a0\u00a0\u00a0total+= values[v];<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.15;margin-top: 0pt;margin-bottom: 0pt\"><span style=\"font-size: 16px;font-family: Arial;color: #000000;background-color: transparent;font-weight: normal;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\">\u00a0\u00a0\u00a0\u00a0\u00a0count++;<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.15;margin-top: 0pt;margin-bottom: 0pt\"><span style=\"font-size: 16px;font-family: Arial;color: #000000;background-color: transparent;font-weight: normal;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\">\u00a0\u00a0\u00a0}<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.15;margin-top: 0pt;margin-bottom: 0pt\"><span style=\"font-size: 16px;font-family: Arial;color: #000000;background-color: transparent;font-weight: normal;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\">\u00a0} else {<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.15;margin-top: 0pt;margin-bottom: 0pt\"><span style=\"font-size: 16px;font-family: Arial;color: #000000;background-color: transparent;font-weight: normal;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\">\u00a0\u00a0\u00a0var count = 0;<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.15;margin-top: 0pt;margin-bottom: 0pt\"><span style=\"font-size: 16px;font-family: Arial;color: #000000;background-color: transparent;font-weight: normal;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 total = 0;<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.15;margin-top: 0pt;margin-bottom: 0pt\"><span style=\"font-size: 16px;font-family: Arial;color: #000000;background-color: transparent;font-weight: normal;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\">\u00a0\u00a0\u00a0for (v in values) {<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.15;margin-top: 0pt;margin-bottom: 0pt\"><span style=\"font-size: 16px;font-family: Arial;color: #000000;background-color: transparent;font-weight: normal;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\">\u00a0\u00a0\u00a0\u00a0\u00a0total += values[v][&#8216;total&#8217;];<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.15;margin-top: 0pt;margin-bottom: 0pt\"><span style=\"font-size: 16px;font-family: Arial;color: #000000;background-color: transparent;font-weight: normal;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\">\u00a0\u00a0\u00a0\u00a0\u00a0count += values[v][&#8216;count&#8217;];<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.15;margin-top: 0pt;margin-bottom: 0pt\"><span style=\"font-size: 16px;font-family: Arial;color: #000000;background-color: transparent;font-weight: normal;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\">\u00a0\u00a0\u00a0} \u00a0\u00a0\u00a0<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.15;margin-top: 0pt;margin-bottom: 0pt\"><span style=\"font-size: 16px;font-family: Arial;color: #000000;background-color: transparent;font-weight: normal;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\">\u00a0}<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.15;margin-top: 0pt;margin-bottom: 0pt\"><span style=\"font-size: 16px;font-family: Arial;color: #000000;background-color: transparent;font-weight: normal;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\">\u00a0var average = total \/ count;<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.15;margin-top: 0pt;margin-bottom: 0pt\"><span style=\"font-size: 16px;font-family: Arial;color: #000000;background-color: transparent;font-weight: normal;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\">\u00a0return {count: count,<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.15;margin-top: 0pt;margin-bottom: 0pt\"><span style=\"font-size: 16px;font-family: Arial;color: #000000;background-color: transparent;font-weight: normal;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0total: total,<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.15;margin-top: 0pt;margin-bottom: 0pt\"><span style=\"font-size: 16px;font-family: Arial;color: #000000;background-color: transparent;font-weight: normal;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0average: average};<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.15;margin-top: 0pt;margin-bottom: 0pt\"><span style=\"font-size: 16px;font-family: Arial;color: #000000;background-color: transparent;font-weight: normal;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\">}<\/span><\/p>\n<p>&nbsp;<\/p>\n<p dir=\"ltr\" style=\"line-height: 1.15;margin-top: 0pt;margin-bottom: 0pt\"><span style=\"font-size: 16px;font-family: Arial;color: #000000;background-color: transparent;font-weight: normal;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\">Output should look like this in Couchbase view editor:<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/uQcbY4U7CHa_NMkyC86tx5TotRpmoDQavkvViu3KAWPhhjGj5lBMHv_iZiq4MPg1r9FeFwIlVlgT-PqIOEYP8zszpyJTeiIlLtnYgApxFCAuj6G_bWPRdB8J\" width=\"633px;\" height=\"246px;\" \/><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.15;margin-top: 0pt;margin-bottom: 0pt\"><span style=\"font-size: 16px;font-family: Arial;color: #000000;background-color: transparent;font-weight: normal;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\">Before running the query, it is necessary to specify reduce to true:<\/span><\/p>\n<p><img decoding=\"async\" id=\"docs-internal-guid-34046edc-d504-b7b3-42e6-f75b9a8b9bc4\" style=\"width: 230px;height: 260px\" src=\"https:\/\/lh3.googleusercontent.com\/qzhQJwubseJUErE-9_4U96QGyfEYdqeBcl8TZm3t2AI5BPQCvAUF81zNJfz_B1FRJv-_2cX5_XO3XOaO8_p0Srl5JQShsxBakn7oQTBt8IG32mezQMsOeENE\" \/><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.15;margin-top: 0pt;margin-bottom: 0pt\"><span style=\"font-size: 16px;font-family: Arial;color: #000000;background-color: transparent;font-weight: normal;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\">Once the view has been created and saved, click on Show Results and this will display a single line with the average document size, similar to this:<\/span><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/lh3.googleusercontent.com\/d4n5yJPo6wGRqAPwuAJTQXLlxXIDcQo1V2Z-yz8HK4p-Kg1Ab1lt44butkwCbi5DnuhqpWc1gA3rXI_o4U0ypQcerEdcSjORWji6uOKw_hbrI0Fdld8cQymm\" width=\"652px;\" height=\"141px;\" \/><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.15;margin-top: 0pt;margin-bottom: 0pt\"><span style=\"font-size: 15px;font-family: Arial;color: #000000;background-color: transparent;font-weight: normal;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\">Voila!<\/span><\/p>\n<p><span style=\"font-size: 15px;font-family: Arial;color: #000000;background-color: transparent;font-weight: normal;font-style: normal;font-variant: normal;text-decoration: none;vertical-align: baseline\">Please send comments and questions at alexis@couchbase.com<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Couchbase offers an unique NoSQL database combining integrated cache and storage technology. Many customers and prospects are using it to store binary data and\/or JSON documents. Often; it is necessary to determine average document size to be able to properly [&hellip;]<\/p>\n","protected":false},"author":15,"featured_media":13873,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[1],"tags":[],"ppma_author":[8994],"class_list":["post-1524","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.7.1 (Yoast SEO v25.7) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Calculate average document size using views in Couchbase<\/title>\n<meta name=\"description\" content=\"Learn more about Couchbase sizing. Check out a simple way to calculate average document size (for binary data and JSON documents) using views.\" \/>\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.couchbase.com\/blog\/calculating-average-document-size-documents-stored-couchbase\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Calculating average document size of documents stored in Couchbase.\" \/>\n<meta property=\"og:description\" content=\"Learn more about Couchbase sizing. Check out a simple way to calculate average document size (for binary data and JSON documents) using views.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.couchbase.com\/blog\/calculating-average-document-size-documents-stored-couchbase\/\" \/>\n<meta property=\"og:site_name\" content=\"The Couchbase Blog\" \/>\n<meta property=\"article:published_time\" content=\"2014-12-16T19:21:06+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-06-28T07:42:15+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/lh4.googleusercontent.com\/uQcbY4U7CHa_NMkyC86tx5TotRpmoDQavkvViu3KAWPhhjGj5lBMHv_iZiq4MPg1r9FeFwIlVlgT-PqIOEYP8zszpyJTeiIlLtnYgApxFCAuj6G_bWPRdB8J\" \/>\n<meta name=\"author\" content=\"Alexis Roos\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Alexis Roos\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/calculating-average-document-size-documents-stored-couchbase\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/calculating-average-document-size-documents-stored-couchbase\/\"},\"author\":{\"name\":\"Alexis Roos\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/590e3e4872f83fe795d5a39eef3f9fae\"},\"headline\":\"Calculating average document size of documents stored in Couchbase.\",\"datePublished\":\"2014-12-16T19:21:06+00:00\",\"dateModified\":\"2023-06-28T07:42:15+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/calculating-average-document-size-documents-stored-couchbase\/\"},\"wordCount\":558,\"commentCount\":5,\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/calculating-average-document-size-documents-stored-couchbase\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/calculating-average-document-size-documents-stored-couchbase\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/calculating-average-document-size-documents-stored-couchbase\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/calculating-average-document-size-documents-stored-couchbase\/\",\"name\":\"Calculate average document size using views in Couchbase\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/calculating-average-document-size-documents-stored-couchbase\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/calculating-average-document-size-documents-stored-couchbase\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"datePublished\":\"2014-12-16T19:21:06+00:00\",\"dateModified\":\"2023-06-28T07:42:15+00:00\",\"description\":\"Learn more about Couchbase sizing. Check out a simple way to calculate average document size (for binary data and JSON documents) using views.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/calculating-average-document-size-documents-stored-couchbase\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/calculating-average-document-size-documents-stored-couchbase\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/calculating-average-document-size-documents-stored-couchbase\/#primaryimage\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"width\":1800,\"height\":630},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/calculating-average-document-size-documents-stored-couchbase\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.couchbase.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Calculating average document size of documents stored in Couchbase.\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"name\":\"The Couchbase Blog\",\"description\":\"Couchbase, the NoSQL Database\",\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\",\"name\":\"The Couchbase Blog\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"width\":218,\"height\":34,\"caption\":\"The Couchbase Blog\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/590e3e4872f83fe795d5a39eef3f9fae\",\"name\":\"Alexis Roos\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/0ab9bfaebda64901a6d385eb29a1eb04\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/1af4f7380fe5fbd14381a9496c85b09b40d47524abcf8d3c68706a59b80c00c7?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/1af4f7380fe5fbd14381a9496c85b09b40d47524abcf8d3c68706a59b80c00c7?s=96&d=mm&r=g\",\"caption\":\"Alexis Roos\"},\"description\":\"Alexis Roos is senior engineering manager at Salesforce. Alexis has over 20 years of software engineering experience with the last five years focused on large-scale data science and engineering, working for SIs in Europe, Sun Microsystems\/Oracle, and several startups, including Radius Intelligence, Concurrent, and Couchbase.\",\"url\":\"https:\/\/www.couchbase.com\/blog\/author\/alexis-roos\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Calculate average document size using views in Couchbase","description":"Learn more about Couchbase sizing. Check out a simple way to calculate average document size (for binary data and JSON documents) using views.","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.couchbase.com\/blog\/calculating-average-document-size-documents-stored-couchbase\/","og_locale":"en_US","og_type":"article","og_title":"Calculating average document size of documents stored in Couchbase.","og_description":"Learn more about Couchbase sizing. Check out a simple way to calculate average document size (for binary data and JSON documents) using views.","og_url":"https:\/\/www.couchbase.com\/blog\/calculating-average-document-size-documents-stored-couchbase\/","og_site_name":"The Couchbase Blog","article_published_time":"2014-12-16T19:21:06+00:00","article_modified_time":"2023-06-28T07:42:15+00:00","og_image":[{"url":"https:\/\/lh4.googleusercontent.com\/uQcbY4U7CHa_NMkyC86tx5TotRpmoDQavkvViu3KAWPhhjGj5lBMHv_iZiq4MPg1r9FeFwIlVlgT-PqIOEYP8zszpyJTeiIlLtnYgApxFCAuj6G_bWPRdB8J","type":"","width":"","height":""}],"author":"Alexis Roos","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Alexis Roos","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.couchbase.com\/blog\/calculating-average-document-size-documents-stored-couchbase\/#article","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/calculating-average-document-size-documents-stored-couchbase\/"},"author":{"name":"Alexis Roos","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/590e3e4872f83fe795d5a39eef3f9fae"},"headline":"Calculating average document size of documents stored in Couchbase.","datePublished":"2014-12-16T19:21:06+00:00","dateModified":"2023-06-28T07:42:15+00:00","mainEntityOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/calculating-average-document-size-documents-stored-couchbase\/"},"wordCount":558,"commentCount":5,"publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/calculating-average-document-size-documents-stored-couchbase\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.couchbase.com\/blog\/calculating-average-document-size-documents-stored-couchbase\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.couchbase.com\/blog\/calculating-average-document-size-documents-stored-couchbase\/","url":"https:\/\/www.couchbase.com\/blog\/calculating-average-document-size-documents-stored-couchbase\/","name":"Calculate average document size using views in Couchbase","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/calculating-average-document-size-documents-stored-couchbase\/#primaryimage"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/calculating-average-document-size-documents-stored-couchbase\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","datePublished":"2014-12-16T19:21:06+00:00","dateModified":"2023-06-28T07:42:15+00:00","description":"Learn more about Couchbase sizing. Check out a simple way to calculate average document size (for binary data and JSON documents) using views.","breadcrumb":{"@id":"https:\/\/www.couchbase.com\/blog\/calculating-average-document-size-documents-stored-couchbase\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.couchbase.com\/blog\/calculating-average-document-size-documents-stored-couchbase\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/calculating-average-document-size-documents-stored-couchbase\/#primaryimage","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","width":1800,"height":630},{"@type":"BreadcrumbList","@id":"https:\/\/www.couchbase.com\/blog\/calculating-average-document-size-documents-stored-couchbase\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.couchbase.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Calculating average document size of documents stored in Couchbase."}]},{"@type":"WebSite","@id":"https:\/\/www.couchbase.com\/blog\/#website","url":"https:\/\/www.couchbase.com\/blog\/","name":"The Couchbase Blog","description":"Couchbase, the NoSQL Database","publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.couchbase.com\/blog\/#organization","name":"The Couchbase Blog","url":"https:\/\/www.couchbase.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","width":218,"height":34,"caption":"The Couchbase Blog"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/590e3e4872f83fe795d5a39eef3f9fae","name":"Alexis Roos","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/0ab9bfaebda64901a6d385eb29a1eb04","url":"https:\/\/secure.gravatar.com\/avatar\/1af4f7380fe5fbd14381a9496c85b09b40d47524abcf8d3c68706a59b80c00c7?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/1af4f7380fe5fbd14381a9496c85b09b40d47524abcf8d3c68706a59b80c00c7?s=96&d=mm&r=g","caption":"Alexis Roos"},"description":"Alexis Roos is senior engineering manager at Salesforce. Alexis has over 20 years of software engineering experience with the last five years focused on large-scale data science and engineering, working for SIs in Europe, Sun Microsystems\/Oracle, and several startups, including Radius Intelligence, Concurrent, and Couchbase.","url":"https:\/\/www.couchbase.com\/blog\/author\/alexis-roos\/"}]}},"authors":[{"term_id":8994,"user_id":15,"is_guest":0,"slug":"alexis-roos","display_name":"Alexis Roos","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/1af4f7380fe5fbd14381a9496c85b09b40d47524abcf8d3c68706a59b80c00c7?s=96&d=mm&r=g","author_category":"","last_name":"Roos","first_name":"Alexis","job_title":"","user_url":"","description":"Alexis Roos is senior engineering manager at Salesforce. Alexis has over 20 years of software engineering experience with the last five years focused on large-scale data science and engineering, working for SIs in Europe, Sun Microsystems\/Oracle, and several startups, including Radius Intelligence, Concurrent, and Couchbase."}],"_links":{"self":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/1524","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/users\/15"}],"replies":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/comments?post=1524"}],"version-history":[{"count":0,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/1524\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media\/13873"}],"wp:attachment":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media?parent=1524"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/categories?post=1524"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/tags?post=1524"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=1524"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}