Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Mongoose for Application Development

You're reading from   Mongoose for Application Development Mongoose streamlines application development on the Node.js stack and this book is the ideal guide to both the concepts and practical application. From connecting to a database to re-usable plugins, it's all here.

Arrow left icon
Product type Paperback
Published in Aug 2013
Publisher Packt
ISBN-13 9781782168195
Length 142 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Simon Holmes Simon Holmes
Author Profile Icon Simon Holmes
Simon Holmes
Arrow right icon
View More author details
Toc

Table of Contents (18) Chapters Close

Mongoose for Application Development
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1. Introducing Mongoose to the Technology Stack FREE CHAPTER 2. Establishing a Database Connection 3. Schemas and Models 4. Interacting with Data – an Introduction 5. Interacting with Data – Creation 6. Interacting with Data – Reading, Querying, and Finding 7. Interacting with Data – Updating 8. Interacting with Data – Deleting 9. Validating Data 10. Complex Schemas 11. Plugins – Re-using Code Index

Mongoose validation – the basics


In Mongoose, validation is set at the schema level. Remember how in our userSchema we have this for the email field:

  email: { type: String, unique: true }

The unique: true part is a type of validation that Mongoose passes directly through to MongoDB. The other types of validation we are about to look at are set in the same place, but are handled by Mongoose before it goes anywhere near the database; unless of course, you have a type of validation where you specifically choose to check against something in the database.

Default validators

Mongoose provides some common validators to get us started. We'll look at them in this chapter. Some of these are for specific SchemaTypes, which we'll get to know in a moment, but there is one that can be used on all SchemaTypes.

All SchemaTypes

There is one validator that can be used by any SchemaType, named required. This will return a validation error if no data is given to a data object with this property. It is super-easy...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime