1.0.0 • Published 4 years ago

cookbook-database v1.0.0

Weekly downloads
3
License
ISC
Repository
-
Last release
4 years ago

General Assembly Logo

Mongoose Cookbook Authors

Follow along as I build out a very simple application to demonstrate:

  • Defining Mongoose Schemas and Models
  • Validating a Schema
  • Querying a Schema

Instructions

  1. Clone this repository.
  2. Change into the new directory.
  3. Install dependencies.

Solution code is available on the solution branch.

Step 1: Connect to Mongoose

Establish a connection to the database inside of a connection.js file. You'll need to install mongoose for that and have your MongoDB database running!

Step 2: Define a Schema

Use the mongoose Schema class to define a schema for an Author. Then use mongoose.model() to turn it into a model.

Step 3: Validate Your Schema

Add custom validation to your schema. This will ensure objects stored in the collection are consistent!

Step 4: Query Your Model

This is a tease of a future lesson. We're going to demonstrate simple queries, so that we can see that our model is doing what it's supposed to be. Namely: interfacing with MongoDB!

License

  1. All content is licensed under a CC­BY­NC­SA 4.0 license.
  2. All software code is licensed under GNU GPLv3. For commercial use or alternative licensing, please contact legal@ga.co.