Mongoose JS Tutorial - 2 - Schema Design

Veröffentlicht am: 29 Januar 2016
auf dem Kanal: JsWiz
72,344
444

Full Course: https://goo.gl/rT7o2k

Learn how to build a Book Schema and export it to other files.

Let's build a mongoose Schema to represent the data types we just talked about. In a later video we'll be digging into the mongoose API in more detail, but for now we'll tackle the most used aspect of mongoose - which is the creation and usage of Schema's.

We'll start by creating a file called book.model.js. You can think of a model as the basis of a database architecture. So each Schema that we build will have this file name structure. Lets start by defining some variables. First we input mongoose. We're going to be creating Schemas - which is a method we get from mongoose. And we need to export the Schema we created so we can use it in other files.

When setting up our key/value pairs we can either set them up directly. Or as an object. I usually only set it up as an object if I'm using optional fields. For example, one option we can pass is a required field - if this is set to True, then a user must input a title otherwise the data won't get saved. Another very common optional field is unique - you'll see this one most often used with email addresses requiring the user to provide an input that has not been used yet.


Auf dieser Seite können Sie das Online-Video Mongoose JS Tutorial - 2 - Schema Design mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer JsWiz 29 Januar 2016 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 72,344 Mal angesehen und es wurde von 444 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!