Menu
CoddyTech

A Book as a Document

Part of the Databases with MongoDB section of Coddy's Node.js journey. Lesson 1 of 29.

A database stores information so an application can read it later. MongoDB stores each item as a document: an object with named fields. One book can be one document. Its title is text and its year is a number.

{ title: 'Dune', year: 1965 }

A field name tells you what a value means. Two books can have the same field names and different values. Documents are stored in named groups called collections. The provided database already holds three books. Open the Data tab after Run to see their fields; you do not need to write database calls yet.

Types matter when querying: the numeric value 1987 differs from the text '1987'. A query for a numeric year does not match a year stored as text.

challenge icon

Challenge

Easy

This is a small practice project. Its setup is provided; edit only exercise.js.

Return an object describing a fourth book: title Beloved and year 1987. Use a number for year. GET /result must show {"title":"Beloved","year":1987}. This step describes the book; inserting it comes later.

Try it yourself

export function exercise() {
    return null;
}

All lessons in Databases with MongoDB

Practice on your own: Express playground