Full stack web development Course | 115. SWAG SHOP API: CREATING MODELS

Опубликовано: 01 Январь 1970
на канале: WB Web Development Solutions
5,230
51

Full-stack web development Tutorial in Just 3 Weeks

Week 3: Day 2
Section 12: Intro to Node, Mongo, & REST APIs
Tutorial 115: Swag Shop API: Creating the Models

In this video tutorial, we are going to create a model that defines the data we are gonna store. Models are constructors compiled from schema definitions. An instance of a model is called a document. Models are responsible for creating and reading documents from the MongoDB database.
Compiling your first model
When you call mongoose.model() on a schema, mongoose compiles model for you.
In this video for example:
Var mongoose= require( 'mongoose');
Var schema=mongoose. Schema;
Var product = new schema({
Title: string,
Price: number,
Likes:number;})
Module.exports=mongoose. Model('Product',product);
The Model() function makes a copy of a schema. Make sure to add everything into the schema before calling .model().
Constructing documents
An instance of the model is known as a document. It’s easy to create and store a document in the database.
Querying
Using the query syntax of MongoDB we can easily find documents in mongoose. Find, FindOne, where are some of the static methods used.
Deleting
DeleteOne() and deleteMany() are used for deleting documents.
Updating
Update() is used to modify any document.


Смотрите видео Full stack web development Course | 115. SWAG SHOP API: CREATING MODELS онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь WB Web Development Solutions 01 Январь 1970, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 5,23 раз и оно понравилось 5 людям.