Company
Date Published
Author
Alexis Roos
Word count
601
Language
English
Hacker News points
None

Summary

Couchbase's unique NoSQL database combines cache and storage technology, widely used for storing binary data and JSON documents. To properly size a production system, determining the average document size is essential, which can be achieved using views in a development or staging system, though not recommended for production due to the indexing overhead. Views in Couchbase are written in JavaScript and help extract, filter, and aggregate data, beginning with a map function to create an index of key/value pairs, and optionally a reduce function to perform calculations like counting, summing, and averaging document sizes. A map function example is provided, demonstrating how to emit document sizes using JSON.stringify for JSON documents and decodeBase64 for binary documents. A corresponding reduce function aggregates these sizes to calculate an average, showcasing Couchbase's map and reduce constructs, although users report issues with this method in Couchbase version 5.1.