



Let’s talk about an oft-overlooked NoSQL database type. It’s got all the best parts of a k-v store and allows limited SQL-like query-ability too! They’re called document databases and they’re all the rage.A document database stores objects that can be serialized to JSON or some similar serialization format. These JSON ‘documents’ are keyed by an ID, similar to how k-v stores work. When you want to fetch an entire document, all you need is the key for it. But the magic of document databases allows you to fetch only pieces of a document and also to fetch data from multiple documents using selection criteria that mirrors basic SQL query functionality.This is all made possible by the tree-like structure that documents in a doc DB must conform to. JSON data can contain keyed fields, nested structures, and lists. Using this structure a doc DB can extract specific pieces of a doc so that the entire doc doesn’t have to be returned and parsed in the application layer.Query-ability, the other interesting feature of doc DBs, is a step above k-v stores, though not as powerful as a SQL DB. You can filter your results based on different fields in documents since the documents have structure to them. There’s no strict schema, so some docs will have fields that others don’t, but you can still run the same queries on those docs. To improve performance, you can use high-selectivity fields (fields where there are many different possible values among docs) as query filters and add indexes to limit the computation further.Like other NoSQL database types, document databases also enforce no schema. 2 different keys can point to docs with entirely different sets of fields. This means you won’t have to do expensive database migrations each time a new field is needed.MongoDB is the most widely known open source document DB and has all the features listed above as well as many more that will allow you to scale both reads and writes easily. Check it out next chance you get and you’ll certainly find a use for it in one of your projects.