concept schema in category angular

This is an excerpt from Manning's book Getting MEAN with Mongo, Express, Angular, and Node.js 2ED.
Data modeling, in the context of Mongoose and MongoDB, defines what data can be in a document and what data must be in a document. When storing user information, you may want to be able to save the first name, last name, email address, and phone number. But you need only the first name and email address, and the email address must be unique. This information is defined in a schema, which is used as the basis for the data model.
Figure 5.7. Relationships among collections, documents, schemas, and paths in MongoDB and Mongoose, using a business card metaphor
![]()
One final definition is for models. A model is the compiled version of a schema. All data interactions using Mongoose go through the model. You’ll work with models more in chapter 6, but for now, you’re focusing on building them.
Throughout this section, you’ve done quite a bit in the file, so take a look at it all together to see what’s what. The following listing shows the contents of the locations.js file in app_server/models, defining the schema for the location data.
Listing 5.3. Final location schema definition, including nested schemas
const mongoose = require( 'mongoose' ); #1 const openingTimeSchema = new mongoose.Schema({ #2 days: {type: String, required: true}, #2 opening: String, #2 closing: String, #2 closed: { #2 type: Boolean, #2 required: true #2 } #2 }); #2 const reviewSchema = new mongoose.Schema({ #3 author: String, #3 rating: { #3 type: Number, #3 required: true, #3 min: 0, #3 max: 5 #3 }, #3 reviewText: String, #3 createdOn: {type: Date, default: Date.now} #3 }); #3 const locationSchema = new mongoose.Schema({ #4 name: { type: String, required: true }, address: String, rating: { type: Number, 'default': 0, min: 0, max: 5 }, facilities: [String], coords: { type: {type: String }, coordinates:[Number] #5 }, openingTimes: [openingTimeSchema], #6 reviews: [reviewSchema] #6 }); locationSchema.index({coords: '2dsphere'});Documents and subdocuments all have a schema defining their structure, and you’ve also added some default values and basic validation. To make this scenario a bit more real, the following listing shows an example MongoDB document based on this schema.
Anything with the word compiling in it tends to sound a bit complicated. In reality, compiling a Mongoose model from a schema is a simple one-line task. You need to ensure that the schema is complete before you invoke the model command. The model command follows this construct:
In fact, that’s exactly the construct you’re going to use. Add it to the locations.js model, below the line requiring Mongoose. The empty object inside the mongoose-Schema({ }) brackets is where you’ll define the schema.