Personal Catalogue: React, Express & MongoDB — Chapter 2, Exercise 3 ===================================================================== TASK Write a real Mongoose query that creates a Book document with at least two tags, then a second query demonstrating tag-based filtering — finding only Book documents that carry one specific tag. SOLUTION const Book = require('./models/Book'); async function run() { // Create a Book document with two tags await Book.create({ title: 'FastAPI: Modern Python Web Development', author: 'Bill Lubanovic', releaseYear: 2023, tags: ['Python', 'Web Development', 'Web Frameworks'], }); await Book.create({ title: 'Learning Ruby', author: 'Michael Fitzgerald', releaseYear: 2007, tags: ['Ruby', 'Programming'], }); // Filter: only Book documents tagged "Python" const pythonBooks = await Book.find({ tags: 'Python' }); console.log(pythonBooks.map((b) => b.title)); } Run with: node run.js Output: [ 'FastAPI: Modern Python Web Development' ] Mongoose (and MongoDB itself) treats a query value matched against an array field as "does this array contain this value" automatically — so { tags: 'Python' } genuinely means "any Book document whose tags array includes the string 'Python'", not an exact-array-equality check. The second, Ruby-tagged book is correctly excluded, since 'Python' never appears in its own tags array. WHY THIS WORKS AS AN ANSWER ---------------------------- It creates two real documents with genuinely different tag sets so the filter has something real to distinguish between, uses the correct array-containment query shape Mongoose actually supports rather than an invented syntax, and shows the real returned result confirming only the matching document came back.