PacktLib: Mongoose for Application Development

Mongoose for Application Development

Credits

About the Author

About the Reviewers

www.PacktPub.com

Preface

Introducing Mongoose to the Technology Stack

The technology stack – Node.js, npm, MongoDB, and Express

What Mongoose is all about

Installing the full stack

Summary

Establishing a Database Connection

Mongoose default connection

About the connection string

Connection options

Closing the connection

Connection events

Connecting our project

Summary

Schemas and Models

Introducing schemas

Data types allowed in schemas

Where to write the schemas

Writing a schema

Building models

Setting the collection name

Our complete code

Summary

Interacting with Data – an Introduction

Model methods and instance methods

Setting up the project

Summary

Interacting with Data – Creation

Creating an instance

Saving an instance

Creating and saving database entry in one step

CRUD – create data

Summary

Interacting with Data – Reading, Querying, and Finding

Approaches to find and read data

CRUD – reading user and project data

Summary

Interacting with Data – Updating

Model helper methods

The three-step find-edit-save approach

CRUD – editing users and projects

Summary

Interacting with Data – Deleting

Deleting data

CRUD – deleting user and projects

Summary

Validating Data

Mongoose validation – the basics

Understanding validation errors

Doing it your way – create custom validation

Adding validation to our project

Summary

Complex Schemas

Population – references to other collections

Subdocuments

Data management when modifying existing schemas

Summary

Plugins – Re-using Code

Reusable schema plugins

Sharing with the community

Summary

Index