A document database is a database that stores each record as one document, usually written in JSON, the text format that apps already use to send data to each other. It is also called a document store. It is one kind of NoSQL database, a name for databases that do not keep their data in relational tables.
A JSON document is a set of named fields and their values. A value can itself be a list or another set of fields. So one document can hold a whole record, with everything that belongs to it inside.
Imagine a bus ticket booking made in Madurai for an overnight bus to Bengaluru. Three family members travel together. The app saves the booking as one document. It holds the booking number, the bus, the boarding point and the fare of ₹2,850. Inside it is a list of the three passengers, with each one's name, age and seat number: 14, 15 and 16. When the app shows the ticket, it reads this one document in a single step. A relational database would keep the same booking in four tables, the booking, the bus, the passengers and the payment, and join them each time.
Documents in the same collection do not need the same fields. Say the app later adds a field for a passenger's seat preference. New bookings simply include it, and old bookings stay as they are. Nobody has to change a table first. This is why many web and mobile apps start on a document database: the record can change as fast as the app does.
The database still makes searches fast. It keeps an index, a sorted list of the values in one field, such as the travel date. With an index, it finds every booking for 14 November without reading every document. Some document databases also keep the most-used documents in memory, so that an answer comes back within a millisecond. The page on caching explains why that is faster.
The flexibility has a cost. The same detail, such as the bus operator's name, may be copied into thousands of documents. If it changes, every copy must be updated. Questions that combine many kinds of record are harder than in SQL. And each product has its own way of writing queries, so moving to another database later means rewriting them, a form of vendor lock-in.
How is it different from a key-value store? A key-value store finds a record only by its key. A document database can also search on any field inside the document. For analysis, the documents are flattened into tables and copied to a warehouse by change data capture or ETL and ELT tools.