Skip to main content

πŸ¦Έβ€β™€οΈ Enable Validation for the Authors Collection

In this exercise, you will define a JSON schema for the authors collection, apply the schema to the collection, and test the schema validation by inserting a document that does not match the schema.

This is an advanced exercise that requires you to write code. If you get stuck and you're doing this during a live workshop, you can flag down an instructor in the room for help.

  1. Start by opening the server/src/schema-validation/apply-schema.ts file in your GitHub codespace and uncomment lines 41-61.
  2. Complete the tasks marked with // TODO comments.
  3. Execute the script again to apply the schema to the authors collection.
    cd server
    npx tsx src/schema-validation/apply-schema.ts

  4. Finally, test the schema validation by modifying the server/src/schema-validation/test-validation.ts script. Inserting a document in the authors collection.