MongoDB

The Bookshelf API of Express.js keeps its books in a JavaScript array. Restart the process and they are gone; run two copies behind a load balancer and they disagree. Fixing that is MongoDB 1,815 's job, and it is the letter the acronym starts with.

MongoDB stores documents — ordered, typed, nested records that look like JSON objects — in collections instead of rows in tables. A book, its author reference, its tags and its three most recent reviews live in one document and come back in one read, with no join. That is the whole pitch, and it fits the data a web application deals with. It is also the source of every mistake beginners make: the freedom to nest reviews inside a book lets you nest ten thousand of them, past the 16 MB ceiling, where no index reaches.

The version here is MongoDB 8.3, the current stable release; 8.0 and 7.0 are the other supported versions. Everything from The Document Model and BSON on was executed against a local mongod 8.3.11 through mongosh 2.12.0 403 and the driver mongodb 7.6.0, and the transcripts are real. Where a feature needs a replica set, a paid Atlas 1,815 tier or a license the Community build lacks, the text says so rather than inventing output.

Two client libraries matter: the mongodb driver wraps the wire protocol thinly, and Mongoose 9.10.1 243,355 adds schemas, casting, validation and population on top of it. By the end of the chapter the Bookshelf API is backed by a real database with indexes that serve its queries, a schema designed around them, seed data, migrations and tests — a data layer Next.js reuses from Next.js 10,514 .

What you will learn

Sections