MongoDB Working with APIs and Practical Examples

CoderOne · Beginner ·🛠️ AI Tools & Apps ·8y ago

Key Takeaways

This video tutorial covers working with MongoDB and APIs, specifically converting a Pokémon API to use a MongoDB database. It demonstrates how to require MongoDB, create a model, compile the model, and connect to the database.

Full Transcript

have fun on guys how all your doing welcome to new video tutorial on the MongoDB Cruz series so in the last one not cover the basics things about like installing the MongoDB binaries on your machine and setting up everything in just a quick test of how MongoDB works and like the differences between in a rational and a non rational database is like my CEO on a MongoDB the main difference is the major differences between them and I'm actually MongoDB works and why it is very very suitable for Web projects so but for this particular tutorial we're going to do is like convert this pokémons API over here into like from hard-coded the array data like storing the information or the data on like a server-side ray variable into like using it to a real world example for like making this gonna be stored on a real database which is like the MongoDB so if you're not I like knowing what is this pokemon pokemon API thing so in the API store like chemistry on the channel actually so if you have to watch this and we do recommend go ahead watch it because we have explaining all of that like how to make this web server and we've gone through this like step by step explain what is this doing and why it's really important thing in here and everything just going on about this pokemons API so it's pretty much what it does is just go ahead and like we can request some data from this server like client there's a client and there's a server so the client requested data from the server and the server responds with the requested or the needed data from the actual user or from the actual client like getting the pokemons list over you which means this one the names of a bacon oakmoss or adding a specific Pokemon or removing another specific Pokemon so what we're going to do is to make this or so make this one application or this API server supports MongoDB to store the actual data into MongoDB so first things first to get started with actually or we need to like require the MongoDB and actually before that you need to start the service so make sure you have watched and install MongoDB on your machine so just on than the last Oreo run it and make sure that the service is running and also make sure Jonestown mangoes and you're like no DTS project so npm install' mangoes and everything gonna be working fine now we need to start like the mango thing we need to go like mangoes and equals required mangoes so we need to require everything requirement goes over here so mangoes yeah and the other thing we need to like this required up so now I'm typing required now actually we need to like make it the model the actual model like like the model who created the last time the for the user and the password and all this kind of things we need to do it the same for the pokemons in here so in order to make it work and we don't look like to and to be able to like interactive the database save the DNA and fix the DN a-- from there so first things first let's obviously require the mangoes over here so just make sure to like constant mangas require and not you require mangoes over on the top of there and here we create the model and the model gonna be very very simple so let's let's pull him over for example equals or the scanner so we create this camera and like then compile compile it into a model so we do like you scanner and make sure to require the scanner which i haven't already done that so make sure to go up over there and just scan up upper case equals mongos or mongos don't come okay so everything is working fine over here so now I need to go ahead and do this our schema so this gamma gonna be very simple as I've said it takes the first thing in your s the name of the Pokemon so we type in name and like the type of that's going to be a string and is going to be a required thing and the other thing is ability so ability also is going to type of office training and the required gonna be very gonna be true so make sure it's your feel free to use any other attributes for that but this will do the job for us and yeah you can have that other fields in here feel free to run whatever you need over here going to make yours looks better and now we need to compile it into a model so let's let's just call the scanner and let's pokemon equals nominee choose the man goes to top model in order to compile it into real models so we passing the model name we're gonna call it just a pokemon and the fascination list name so you can access this later on from any other like for any piece of code in your project or from either side of your project whenever you compile it then you want to access just call this function without passing in the schema and it's gonna return for you the actual compiled model from schema so this is a really nice feature from manga over here and yeah we need to pass in the modern schema and everything gonna be compiled no need to call or over you I mean on the end this kind of route over here like this route specifically is getting all of the like all of the data on the database so all the dance is just gonna return Vienna the database fetch the data all of the pokemons from the database then return them or send them back into the e user so the user can fit can just display them on when he is like script or like the client pretty much so all this done is just gonna grab grab it from the database and send it out so Jason as you can see in here so status then we send Ian has a pokemons array over here and a Pokemon so gonna be very simple so all we need to do over here let me just testing we need to use our model so the models gonna be used pretty much everywhere so whatever you need to say whenever you need like to fake from the database whenever you need to remove or update any data from the database from on God you need to require the PO or the models the model that you have or you want to access the data into so make sure to click to have that and the model can be compiled of course from this camera so make sure to have that and like find find all pokemons maybe much 1/2 like you forgot about doing pretty much envy like the male most important thing is just connecting database so we haven't like open up a stream or we haven't connects and database actually so let's do that up here so connects to the database and make sure to the connect to the database using just the mongos don't connect and here we put in the stream which we're gonna be like MongoDB and like MongoDB for our protocol and put in localhost we put in like forward slash than our database name which gonna call it just okey okey mom okay pretty simple and here like we're putting the other thing the array or the callback at this toy I'm confusing console without checking for the call so the log connected and yeah here we got not only connected we create the model and everything should be looking fine I really just keep taking me at the end of the file but yeah this is fine now when you're here to like as I've said to look for the database so for that we put in Pokemon doc find and this fine method gonna just give it the first thing so there's like a four of them the first condition is an object and the second one is just gonna a callback runs whenever the gala is being or when whenever the Vienna has been fetch it from the database so the first one is the object of like whatever you want to search for so the earth is the objects we're gonna use here is an empty object since we want to get all of the data from the database which means all of the pokémon listed them there we want to grab them from the other base and just gonna be returned for us and here the second one is going to be as you can see the array all the callback which has the first one is

Original Description

Full Tutorial: http://go.ipenywis.com/ipeny6a8b --- Official Links---- Official Website: http://ipenywis.com Official Facebook: http://go.ipenywis.com/ipeny4907 Official Twitter: http://go.ipenywis.com/islem9a03 Official GitHub Repo: http://go.ipenywis.com/ipeny5c0e ---Support US--- By Becoming a Patreon: http://go.ipenywis.com/ipeny5024
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from CoderOne · CoderOne · 30 of 60

1 Laravel CMS | N-01 | Getting Started and Environment Set Up
Laravel CMS | N-01 | Getting Started and Environment Set Up
CoderOne
2 Laravel CMS | N-02 | Routes, Controllers and Views
Laravel CMS | N-02 | Routes, Controllers and Views
CoderOne
3 Laravel CMS | N-03 | Dealing With Assets and Page Layouts
Laravel CMS | N-03 | Dealing With Assets and Page Layouts
CoderOne
4 Laravel CMS | N-04 | Migration, Models and Adding Categories
Laravel CMS | N-04 | Migration, Models and Adding Categories
CoderOne
5 Laravel CMS | N-05 | Showing Added Categories, and Session Messages
Laravel CMS | N-05 | Showing Added Categories, and Session Messages
CoderOne
6 Laravel CMS | N-06 | Edit\Remove Categories using AJAX and Popups
Laravel CMS | N-06 | Edit\Remove Categories using AJAX and Popups
CoderOne
7 Laravel CMS | N-07 | Add New Post
Laravel CMS | N-07 | Add New Post
CoderOne
8 Laravel CMS | N-08 | Creating a Basic Laravel Blog
Laravel CMS | N-08 | Creating a Basic Laravel Blog
CoderOne
9 HTML5 Canvas For Beginners | Getting Started | #01 with Webpack
HTML5 Canvas For Beginners | Getting Started | #01 with Webpack
CoderOne
10 HTML5 Canvas For Beginners | Drawing Basic Shapes | 02
HTML5 Canvas For Beginners | Drawing Basic Shapes | 02
CoderOne
11 HTML5 Canvas | Drawing Text With Circles | Part 01
HTML5 Canvas | Drawing Text With Circles | Part 01
CoderOne
12 HTML5 Canvas | Text Animation and Circle Collision | Part 02
HTML5 Canvas | Text Animation and Circle Collision | Part 02
CoderOne
13 Complete Guide To Web Development In 2018
Complete Guide To Web Development In 2018
CoderOne
14 AJAX & JSON Explained | Examples
AJAX & JSON Explained | Examples
CoderOne
15 Visual Studio Code Web Development Setup and Extensions
Visual Studio Code Web Development Setup and Extensions
CoderOne
16 Electron Build Desktop Apps HTML/CSS/JS - Getting Started 01
Electron Build Desktop Apps HTML/CSS/JS - Getting Started 01
CoderOne
17 Electron Build Desktop Apps HTML/CSS/JS | Creating Windows and Processes 02
Electron Build Desktop Apps HTML/CSS/JS | Creating Windows and Processes 02
CoderOne
18 Electron Build Desktop Apps HTML\CSS\JS | Dialog, Sessions and Cookies 03
Electron Build Desktop Apps HTML\CSS\JS | Dialog, Sessions and Cookies 03
CoderOne
19 Electron Build Desktop Apps HTML\CSS\JS | Custom App Menu & Context Menu 04
Electron Build Desktop Apps HTML\CSS\JS | Custom App Menu & Context Menu 04
CoderOne
20 Electron Build Desktop Apps HTML\CSS\JS | Package, Build and Deploy your App 05
Electron Build Desktop Apps HTML\CSS\JS | Package, Build and Deploy your App 05
CoderOne
21 Node.js Brief Beginners Introduction #01
Node.js Brief Beginners Introduction #01
CoderOne
22 Node.js How Modules Works & NPM #02
Node.js How Modules Works & NPM #02
CoderOne
23 Node.js Working With Events and Event Emitter #03
Node.js Working With Events and Event Emitter #03
CoderOne
24 Node.js File System (Read and Write) FS 04
Node.js File System (Read and Write) FS 04
CoderOne
25 Node.js Create a Basic Server Using Express 05
Node.js Create a Basic Server Using Express 05
CoderOne
26 Json Web Token Authentication JWT Explained Securing API
Json Web Token Authentication JWT Explained Securing API
CoderOne
27 CSS Flex Box Design | Practical Examples |
CSS Flex Box Design | Practical Examples |
CoderOne
28 API How It Works With Practical Examples
API How It Works With Practical Examples
CoderOne
29 MongoDB Getting Started 01
MongoDB Getting Started 01
CoderOne
MongoDB Working with APIs and Practical Examples
MongoDB Working with APIs and Practical Examples
CoderOne
31 Create a Command Line Interface (CLI) Using Node JS #01
Create a Command Line Interface (CLI) Using Node JS #01
CoderOne
32 Create a Command Line Interface (CLI) Using Node JS 02
Create a Command Line Interface (CLI) Using Node JS 02
CoderOne
33 Build React Apps | Introduction And Getting Started #01
Build React Apps | Introduction And Getting Started #01
CoderOne
34 Build React Apps | Working With Components And Multiple Rendering #02
Build React Apps | Working With Components And Multiple Rendering #02
CoderOne
35 Build React Apps | App State Management | Practical Examples #03
Build React Apps | App State Management | Practical Examples #03
CoderOne
36 Build React Apps | Getting Started With Flux (Intro) #04
Build React Apps | Getting Started With Flux (Intro) #04
CoderOne
37 Build React Apps | Create a Clock Timer Using React 05
Build React Apps | Create a Clock Timer Using React 05
CoderOne
38 Build React Apps | Create a Clock Timer Using React 05 | PART2|
Build React Apps | Create a Clock Timer Using React 05 | PART2|
CoderOne
39 CSS Preprocessors Getting Started | SASS and LESS | Practical Examples
CSS Preprocessors Getting Started | SASS and LESS | Practical Examples
CoderOne
40 Regex Introduction | Learn Regular Expressions 01
Regex Introduction | Learn Regular Expressions 01
CoderOne
41 PHP VS Node.js Which is Best For Web Development
PHP VS Node.js Which is Best For Web Development
CoderOne
42 Drag and Drop Using Native Javascript 01
Drag and Drop Using Native Javascript 01
CoderOne
43 Drag And Drop Using Native Javascript 02
Drag And Drop Using Native Javascript 02
CoderOne
44 Master Git (Version Control) in One Video From Scratch
Master Git (Version Control) in One Video From Scratch
CoderOne
45 Let's Learn The New Javascript ES6 Class Syntax
Let's Learn The New Javascript ES6 Class Syntax
CoderOne
46 Let's Create A BlockChain On Node.js
Let's Create A BlockChain On Node.js
CoderOne
47 Best Online Code Editors For Web Developers
Best Online Code Editors For Web Developers
CoderOne
48 Let's Create a Modern Login Form on React #01
Let's Create a Modern Login Form on React #01
CoderOne
49 Let's Create a Modern Login Form on React #02
Let's Create a Modern Login Form on React #02
CoderOne
50 Laravel CMS | N-09 | Admin Registration
Laravel CMS | N-09 | Admin Registration
CoderOne
51 Laravel CMS | N-10 | Login and Authentication
Laravel CMS | N-10 | Login and Authentication
CoderOne
52 Let's Create a Twitter Bot (Listen and Retweet)
Let's Create a Twitter Bot (Listen and Retweet)
CoderOne
53 Rapid Webpage Creation With Emmet (HTML & CSS)
Rapid Webpage Creation With Emmet (HTML & CSS)
CoderOne
54 Create Popups and Modals Using Native Javascript, HTML and CSS
Create Popups and Modals Using Native Javascript, HTML and CSS
CoderOne
55 Promises and Callbacks on Javascript With Practical Examples
Promises and Callbacks on Javascript With Practical Examples
CoderOne
56 Create Collapses using Native Javascript, HTML and CSS
Create Collapses using Native Javascript, HTML and CSS
CoderOne
57 Let's Learn Typescript (Javascript Devs) | Getting Started 01
Let's Learn Typescript (Javascript Devs) | Getting Started 01
CoderOne
58 Let's Learn Typescript | Interfaces and Generic Types (The Typing System) 02
Let's Learn Typescript | Interfaces and Generic Types (The Typing System) 02
CoderOne
59 Let's Learn Typescript | Work With Classes, Modules and Enums 03
Let's Learn Typescript | Work With Classes, Modules and Enums 03
CoderOne
60 Let's Learn Typescript | React and Webpack With TS 04
Let's Learn Typescript | React and Webpack With TS 04
CoderOne

This video tutorial teaches how to convert a Pokémon API to use a MongoDB database, covering topics such as requiring MongoDB, creating a model, and connecting to the database. It provides a practical example of working with MongoDB and APIs.

Key Takeaways
  1. Require MongoDB
  2. Create a Mongoose model
  3. Compile the model
  4. Connect to the database
  5. Use the model to interact with the database
💡 Using a MongoDB database can simplify data storage and retrieval for APIs, especially those with complex or dynamic data structures.

Related AI Lessons

Up next
I Asked ChatGPT to Apply to 500 Jobs (8 Interviews in 48 Hours)
Sabrina Ramonov 🍄
Watch →