#80 Aliasing a route | Using MongoDB with Express| A Complete NODE JS Course

  Рет қаралды 4,534

procademy

procademy

Күн бұрын

Пікірлер: 11
@parth_patel2933
@parth_patel2933 7 ай бұрын
you are the only youtuber who teaching node js in detail. its amazing. thanks
@mohamedibrahemsaad573
@mohamedibrahemsaad573 3 ай бұрын
you are the king of this platform!
@AjayCoding
@AjayCoding Жыл бұрын
Really Helpful
@ankitSingh-tu5on
@ankitSingh-tu5on Жыл бұрын
Aap projects pr videos kb upload kroge?
@AjayCoding
@AjayCoding Жыл бұрын
👌
@mozammilahmad8431
@mozammilahmad8431 Жыл бұрын
Sir plz is backend ko Angular k sath fronntend me use kijiyega.. MEAN stack project
@imanariyobaptiste8177
@imanariyobaptiste8177 Жыл бұрын
I LIKE IT
@dh1569
@dh1569 3 ай бұрын
Anyone have the corrected code for this lesson. All this does is return All Movies.
@rbedson8965
@rbedson8965 2 ай бұрын
we can use if statement to check if sort==='-ratings' && limit==='5' and then use MovieModel.find(query).sort('-ratings).limit(5) and return the data accordingly and for normal usage, whatever we have done earlier is good enough
@harishbabus.r3957
@harishbabus.r3957 9 күн бұрын
//to get the highest rated movies exports.getHighestRated = (req,res, next)=>{ //creating our own query req.query.limit = '5'; req.query.sort = '-ratings'; next(); } //1)get all movies callback exports.getAllMovies = async(req,res)=>{ //.find() method is used to query documents or get documents from mongodb try { // This approach is for mongoose version 6.0 or less // const excludeFields = ["sort", "page", "limit", "fields"]; // const queryObj = {...req.query}; // //delete the properties not required // excludeFields.forEach((el)=>{ // delete queryObj[el] // }); // let movies = await Movie.find(queryObj); //logic for more complex filters let queryStr = JSON.stringify(req.query); //converting as string queryStr = queryStr.replace(/\b(gte|gt|lte|lt)\b/g,(match)=> `$${match}`); //adding $ to query string const queryObj = JSON.parse(queryStr); //converting to JSON Object console.log(queryObj) let query = Movie.find(queryObj); let query1 = Movie.find(); //query object, we can perform query methods like sort etc //Sorting Logic if(req.query.sort){ const sortBy = req.query.sort.split(',').join(' '); //making multiple sort query with space query = query1.sort(sortBy) }else { //it should sort based created date query = query.sort("-createdAt") //descending order } //Limiting Fields(include or exclude fields) if(req.query.fields){ //query.select('name duration price ratings') const fields = req.query.fields.split(',').join(' '); query = query1.select(fields); }else { //default need to exclude __v field query.select('-__v'); //use - symbol to exclude field } //PAGINATION using .skip().limit() method const page = req.query.page*1 || 1; //converting as number and default value const limit = req.query.limit*1 ||10; //PAGE 1: 1-10; PAGE 2: 11-20; PAGE 3 : 21-30 .. const skip = (page - 1)*limit; //calculating count for skip console.log(skip) query = query1.skip(skip).limit(limit); if(req.query.page) { //to handle error const moviesCount = await Movie.countDocuments(); if(skip >= moviesCount) { throw new Error("This page is not found!"); } } let movies = await query; res.status(200).json({ status : "Success", length : movies.length, data : { movies : movies } }) }catch(err){ res.status(404).json({ status : "fail", message : err.message }) } }
@chinmayeemahapatra504
@chinmayeemahapatra504 Жыл бұрын
Could you please provide source code link for node project
Connecting NodeJS with MongoDB | Mongoose + Express
19:18
Piyush Garg
Рет қаралды 161 М.
Try this prank with your friends 😂 @karina-kola
00:18
Andrey Grechka
Рет қаралды 9 МЛН
Don’t Choose The Wrong Box 😱
00:41
Topper Guild
Рет қаралды 62 МЛН
How To Use TypeScript With Express & Node
17:05
Colt Steele
Рет қаралды 75 М.
What is Database Sharding?
9:05
Anton Putra
Рет қаралды 68 М.
Solving one of PostgreSQL's biggest weaknesses.
17:12
Dreams of Code
Рет қаралды 222 М.
Node js Course 2022 - #expressjs #mongodb  with #nodejs
3:34:16
Bitfumes
Рет қаралды 31 М.
Angular is about to get its most IMPORTANT change in a long time...
10:15
Microservices with Databases can be challenging...
20:52
Software Developer Diaries
Рет қаралды 116 М.
JavaScript Visualized - Event Loop, Web APIs, (Micro)task Queue
12:35
MongoDB Crash Course 2022
27:22
Traversy Media
Рет қаралды 205 М.