1.0.0 • Published 4 years ago
cookbook-database v1.0.0
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 legal@ga.co.
1.0.0
4 years ago