cookbook-database
v1.0.0
Published
[![General Assembly Logo](https://camo.githubusercontent.com/1a91b05b8f4d44b5bbfb83abac2b0996d8e26c92/687474703a2f2f692e696d6775722e636f6d2f6b6538555354712e706e67)](https://generalassemb.ly/education/web-development-immersive)
Downloads
4
Readme
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
- Clone this repository.
- Change into the new directory.
- 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
- All content is licensed under a CCBYNCSA 4.0 license.
- All software code is licensed under GNU GPLv3. For commercial use or alternative licensing, please contact [email protected].